blob: 1570dc8d07652dbc5e83313e6176a766f533943a [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
439unsigned long acpi_create_dmar_drhd_ds_pci(unsigned long current, u8 segment,
440 u8 dev, u8 fn)
441{
442 dev_scope_t *ds = (dev_scope_t *)current;
443 memset(ds, 0, sizeof(*ds));
444 ds->type = SCOPE_PCI_ENDPOINT;
445 ds->length = sizeof(*ds) + 2; /* we don't support longer paths yet */
446 ds->start_bus = segment;
447 ds->path[0].dev = dev;
448 ds->path[0].fn = fn;
449
450 return ds->length;
451}
452
Uwe Hermann622824c2010-11-19 15:14:42 +0000453/* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */
Vladimir Serbinenko5e597572014-10-11 23:45:40 +0200454void acpi_create_slit(acpi_slit_t *slit,
455 unsigned long (*acpi_fill_slit)(unsigned long current))
Yinghai Lud4b278c2006-10-04 20:46:15 +0000456{
Uwe Hermann622824c2010-11-19 15:14:42 +0000457 acpi_header_t *header = &(slit->header);
458 unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000459
Uwe Hermann622824c2010-11-19 15:14:42 +0000460 memset((void *)slit, 0, sizeof(acpi_slit_t));
Yinghai Lud4b278c2006-10-04 20:46:15 +0000461
Uwe Hermann622824c2010-11-19 15:14:42 +0000462 /* Fill out header fields. */
463 memcpy(header->signature, "SLIT", 4);
464 memcpy(header->oem_id, OEM_ID, 6);
465 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
466 memcpy(header->asl_compiler_id, ASLC, 4);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000467
Uwe Hermann622824c2010-11-19 15:14:42 +0000468 header->length = sizeof(acpi_slit_t);
469 header->revision = 1; /* ACPI 1.0: N/A, ACPI 2.0/3.0/4.0: 1 */
Yinghai Lud4b278c2006-10-04 20:46:15 +0000470
Uwe Hermann622824c2010-11-19 15:14:42 +0000471 current = acpi_fill_slit(current);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000472
Uwe Hermann622824c2010-11-19 15:14:42 +0000473 /* (Re)calculate length and checksum. */
474 header->length = current - (unsigned long)slit;
475 header->checksum = acpi_checksum((void *)slit, header->length);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000476}
477
Uwe Hermann622824c2010-11-19 15:14:42 +0000478/* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */
Stefan Reinauer777224c2005-01-19 14:06:41 +0000479void acpi_create_hpet(acpi_hpet_t *hpet)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000480{
Uwe Hermann622824c2010-11-19 15:14:42 +0000481 acpi_header_t *header = &(hpet->header);
482 acpi_addr_t *addr = &(hpet->addr);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000483
Stefan Reinauera7648c22004-01-29 17:31:34 +0000484 memset((void *)hpet, 0, sizeof(acpi_hpet_t));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000485
Uwe Hermann622824c2010-11-19 15:14:42 +0000486 /* Fill out header fields. */
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000487 memcpy(header->signature, "HPET", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000488 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000489 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000490 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000491
Stefan Reinauer688b3852004-01-28 16:56:14 +0000492 header->length = sizeof(acpi_hpet_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000493 header->revision = 1; /* Currently 1. Table added in ACPI 2.0. */
Stefan Reinauer688b3852004-01-28 16:56:14 +0000494
Uwe Hermann622824c2010-11-19 15:14:42 +0000495 /* Fill out HPET address. */
496 addr->space_id = 0; /* Memory */
497 addr->bit_width = 64;
498 addr->bit_offset = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200499 addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff;
500 addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000501
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200502 hpet->id = *(unsigned int*)CONFIG_HPET_ADDRESS;
Uwe Hermann622824c2010-11-19 15:14:42 +0000503 hpet->number = 0;
Patrick Georgi9aeb6942012-10-05 21:54:38 +0200504 hpet->min_tick = CONFIG_HPET_MIN_TICKS;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000505
Uwe Hermann622824c2010-11-19 15:14:42 +0000506 header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000507}
Uwe Hermann622824c2010-11-19 15:14:42 +0000508
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200509unsigned long acpi_write_hpet(device_t device, unsigned long current, acpi_rsdp_t *rsdp)
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200510{
511 acpi_hpet_t *hpet;
512
513 /*
514 * We explicitly add these tables later on:
515 */
516 printk(BIOS_DEBUG, "ACPI: * HPET\n");
517
518 hpet = (acpi_hpet_t *) current;
519 current += sizeof(acpi_hpet_t);
520 current = ALIGN(current, 16);
521 acpi_create_hpet(hpet);
522 acpi_add_table(rsdp, hpet);
523
524 return current;
525}
526
Stefan Reinauer777224c2005-01-19 14:06:41 +0000527void acpi_create_facs(acpi_facs_t *facs)
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000528{
Uwe Hermann622824c2010-11-19 15:14:42 +0000529 memset((void *)facs, 0, sizeof(acpi_facs_t));
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000530
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000531 memcpy(facs->signature, "FACS", 4);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000532 facs->length = sizeof(acpi_facs_t);
533 facs->hardware_signature = 0;
534 facs->firmware_waking_vector = 0;
535 facs->global_lock = 0;
536 facs->flags = 0;
537 facs->x_firmware_waking_vector_l = 0;
538 facs->x_firmware_waking_vector_h = 0;
Uwe Hermann622824c2010-11-19 15:14:42 +0000539 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 +0000540}
Stefan Reinauer777224c2005-01-19 14:06:41 +0000541
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100542static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +0000543{
Uwe Hermann622824c2010-11-19 15:14:42 +0000544 acpi_header_t *header = &(rsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000545
Uwe Hermann622824c2010-11-19 15:14:42 +0000546 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000547 memcpy(header->signature, "RSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100548 memcpy(header->oem_id, oem_id, 6);
549 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000550 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000551
Stefan Reinauer688b3852004-01-28 16:56:14 +0000552 header->length = sizeof(acpi_rsdt_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000553 header->revision = 1; /* ACPI 1.0/2.0/3.0/4.0: 1 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000554
Uwe Hermann622824c2010-11-19 15:14:42 +0000555 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauer688b3852004-01-28 16:56:14 +0000556
Uwe Hermann622824c2010-11-19 15:14:42 +0000557 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000558 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000559}
560
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100561static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id)
Stefan Reinauer14e22772010-04-27 06:56:47 +0000562{
Uwe Hermann622824c2010-11-19 15:14:42 +0000563 acpi_header_t *header = &(xsdt->header);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000564
Uwe Hermann622824c2010-11-19 15:14:42 +0000565 /* Fill out header fields. */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000566 memcpy(header->signature, "XSDT", 4);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100567 memcpy(header->oem_id, oem_id, 6);
568 memcpy(header->oem_table_id, oem_table_id, 8);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000569 memcpy(header->asl_compiler_id, ASLC, 4);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000570
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000571 header->length = sizeof(acpi_xsdt_t);
Uwe Hermann622824c2010-11-19 15:14:42 +0000572 header->revision = 1; /* ACPI 1.0: N/A, 2.0/3.0/4.0: 1 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000573
Uwe Hermann622824c2010-11-19 15:14:42 +0000574 /* Entries are filled in later, we come with an empty set. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000575
Uwe Hermann622824c2010-11-19 15:14:42 +0000576 /* Fix checksum. */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000577 header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t));
578}
579
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100580static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt,
581 acpi_xsdt_t *xsdt, char *oem_id)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000582{
Stefan Reinauerd18faac2009-11-05 18:06:43 +0000583 memset(rsdp, 0, sizeof(acpi_rsdp_t));
Uwe Hermann622824c2010-11-19 15:14:42 +0000584
Stefan Reinauer688b3852004-01-28 16:56:14 +0000585 memcpy(rsdp->signature, RSDP_SIG, 8);
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100586 memcpy(rsdp->oem_id, oem_id, 6);
Uwe Hermann622824c2010-11-19 15:14:42 +0000587
588 rsdp->length = sizeof(acpi_rsdp_t);
Stefan Reinauerdefee172015-06-18 01:11:19 -0700589 rsdp->rsdt_address = (uintptr_t)rsdt;
Uwe Hermann622824c2010-11-19 15:14:42 +0000590
591 /*
592 * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2.
593 *
594 * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
595 * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
596 * revision 0).
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000597 */
598 if (xsdt == NULL) {
Uwe Hermann622824c2010-11-19 15:14:42 +0000599 rsdp->revision = 0;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000600 } else {
Stefan Reinauerdefee172015-06-18 01:11:19 -0700601 rsdp->xsdt_address = (u64)(uintptr_t)xsdt;
Uwe Hermann622824c2010-11-19 15:14:42 +0000602 rsdp->revision = 2;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000603 }
Uwe Hermann622824c2010-11-19 15:14:42 +0000604
605 /* Calculate checksums. */
606 rsdp->checksum = acpi_checksum((void *)rsdp, 20);
607 rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000608}
609
zbaocaf494c82012-04-13 13:57:14 +0800610unsigned long acpi_create_hest_error_source(acpi_hest_t *hest, acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len)
611{
612 acpi_header_t *header = &(hest->header);
613 acpi_hest_hen_t *hen;
614 void *pos;
615 u16 len;
616
617 pos = esd;
618 memset(pos, 0, sizeof(acpi_hest_esd_t));
619 len = 0;
620 esd->type = type; /* MCE */
621 esd->source_id = hest->error_source_count;
622 esd->flags = 0; /* FIRMWARE_FIRST */
623 esd->enabled = 1;
624 esd->prealloc_erecords = 1;
625 esd->max_section_per_record = 0x1;
626
627 len += sizeof(acpi_hest_esd_t);
628 pos = esd + 1;
629
630 switch (type) {
631 case 0: /* MCE */
632 break;
633 case 1: /* CMC */
634 hen = (acpi_hest_hen_t *) (pos);
635 memset(pos, 0, sizeof(acpi_hest_hen_t));
636 hen->type = 3; /* SCI? */
637 hen->length = sizeof(acpi_hest_hen_t);
638 hen->conf_we = 0; /* Configuration Write Enable. */
639 hen->poll_interval = 0;
640 hen->vector = 0;
641 hen->sw2poll_threshold_val = 0;
642 hen->sw2poll_threshold_win = 0;
643 hen->error_threshold_val = 0;
644 hen->error_threshold_win = 0;
645 len += sizeof(acpi_hest_hen_t);
646 pos = hen + 1;
647 break;
648 case 2: /* NMI */
649 case 6: /* AER Root Port */
650 case 7: /* AER Endpoint */
651 case 8: /* AER Bridge */
652 case 9: /* Generic Hardware Error Source. */
653 /* TODO: */
654 break;
655 default:
656 printk(BIOS_DEBUG, "Invalid type of Error Source.");
657 break;
658 }
659 hest->error_source_count ++;
660
661 memcpy(pos, data, data_len);
662 len += data_len;
663 header->length += len;
664
665 return len;
666}
667
668/* ACPI 4.0 */
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100669void acpi_write_hest(acpi_hest_t *hest,
670 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest))
zbaocaf494c82012-04-13 13:57:14 +0800671{
672 acpi_header_t *header = &(hest->header);
673
674 memset(hest, 0, sizeof(acpi_hest_t));
675
676 memcpy(header->signature, "HEST", 4);
677 memcpy(header->oem_id, OEM_ID, 6);
678 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
679 memcpy(header->asl_compiler_id, ASLC, 4);
680 header->length += sizeof(acpi_hest_t);
681 header->revision = 1;
682
683 acpi_fill_hest(hest);
684
685 /* Calculate checksums. */
686 header->checksum = acpi_checksum((void *)hest, header->length);
687}
688
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200689#if IS_ENABLED(CONFIG_COMMON_FADT)
690void acpi_create_fadt(acpi_fadt_t *fadt,acpi_facs_t *facs, void *dsdt)
691{
692 acpi_header_t *header = &(fadt->header);
693
694 memset((void *) fadt, 0, sizeof(acpi_fadt_t));
695 memcpy(header->signature, "FACP", 4);
696 header->length = sizeof(acpi_fadt_t);
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200697 header->revision = 4;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200698 memcpy(header->oem_id, OEM_ID, 6);
699 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
700 memcpy(header->asl_compiler_id, ASLC, 4);
701 header->asl_compiler_revision = 0;
702
703 fadt->firmware_ctrl = (unsigned long) facs;
704 fadt->dsdt = (unsigned long) dsdt;
705
706 fadt->x_firmware_ctl_l = (unsigned long)facs;
707 fadt->x_firmware_ctl_h = 0;
708 fadt->x_dsdt_l = (unsigned long)dsdt;
709 fadt->x_dsdt_h = 0;
710
711 if(IS_ENABLED(CONFIG_SYSTEM_TYPE_LAPTOP)) {
712 fadt->preferred_pm_profile = PM_MOBILE;
713 } else {
714 fadt->preferred_pm_profile = PM_DESKTOP;
715 }
716
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200717 acpi_fill_fadt(fadt);
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200718
719 header->checksum =
720 acpi_checksum((void *) fadt, header->length);
721}
722#endif
723
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200724unsigned long __attribute__ ((weak)) fw_cfg_acpi_tables(unsigned long start)
725{
726 return 0;
727}
728
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200729#define ALIGN_CURRENT current = (ALIGN(current, 16))
730unsigned long write_acpi_tables(unsigned long start)
731{
732 unsigned long current;
733 acpi_rsdp_t *rsdp;
734 acpi_rsdt_t *rsdt;
735 acpi_xsdt_t *xsdt;
736 acpi_fadt_t *fadt;
737 acpi_facs_t *facs;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100738 acpi_header_t *slic_file, *slic;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200739 acpi_header_t *ssdt;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200740 acpi_header_t *dsdt_file, *dsdt;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200741 acpi_mcfg_t *mcfg;
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200742 acpi_tcpa_t *tcpa;
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200743 acpi_madt_t *madt;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100744 struct device *dev;
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200745 unsigned long fw;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200746 size_t slic_size, dsdt_size;
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100747 char oem_id[6], oem_table_id[8];
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200748
749 current = start;
750
751 /* Align ACPI tables to 16byte */
752 ALIGN_CURRENT;
753
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200754 fw = fw_cfg_acpi_tables(current);
755 if (fw)
756 return fw;
757
Patrick Georgic32a52c2015-06-22 21:10:34 +0200758#if CONFIG_COMPILE_IN_DSDT
759 extern char _binary_dsdt_aml_start;
760 extern char _binary_dsdt_aml_end;
761 dsdt_file = (acpi_header_t *)&_binary_dsdt_aml_start;
762 dsdt_size = (size_t)(&_binary_dsdt_aml_end - &_binary_dsdt_aml_start);
763#else
Vladimir Serbinenkoa4cf83d2015-06-02 21:40:29 +0200764 dsdt_file = cbfs_boot_map_with_leak(
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200765 CONFIG_CBFS_PREFIX "/dsdt.aml",
766 CBFS_TYPE_RAW, &dsdt_size);
Patrick Georgic32a52c2015-06-22 21:10:34 +0200767#endif
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200768 if (!dsdt_file) {
769 printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n");
770 return current;
771 }
772
773 if (dsdt_file->length > dsdt_size
774 || dsdt_file->length < sizeof (acpi_header_t)
775 || memcmp(dsdt_file->signature, "DSDT", 4) != 0) {
776 printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n");
777 return current;
778 }
779
Aaron Durbin899d13d2015-05-15 23:39:23 -0500780 slic_file = cbfs_boot_map_with_leak(CONFIG_CBFS_PREFIX "/slic",
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100781 CBFS_TYPE_RAW, &slic_size);
Vladimir Serbinenko2cb29782015-05-31 11:32:09 +0200782 if (slic_file
783 && (slic_file->length > slic_size
784 || slic_file->length < sizeof (acpi_header_t)
785 || memcmp(slic_file->signature, "SLIC", 4) != 0)) {
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100786 slic_file = 0;
787 }
788
789 if (slic_file) {
790 memcpy(oem_id, slic_file->oem_id, 6);
791 memcpy(oem_table_id, slic_file->oem_table_id, 8);
792 } else {
793 memcpy(oem_id, OEM_ID, 6);
794 memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8);
795 }
796
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200797 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
798
799 /* We need at least an RSDP and an RSDT Table */
800 rsdp = (acpi_rsdp_t *) current;
801 current += sizeof(acpi_rsdp_t);
802 ALIGN_CURRENT;
803 rsdt = (acpi_rsdt_t *) current;
804 current += sizeof(acpi_rsdt_t);
805 ALIGN_CURRENT;
806 xsdt = (acpi_xsdt_t *) current;
807 current += sizeof(acpi_xsdt_t);
808 ALIGN_CURRENT;
809
810 /* clear all table memory */
811 memset((void *) start, 0, current - start);
812
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100813 acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id);
814 acpi_write_rsdt(rsdt, oem_id, oem_table_id);
815 acpi_write_xsdt(xsdt, oem_id, oem_table_id);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200816
817 printk(BIOS_DEBUG, "ACPI: * FACS\n");
Patrick Georgi133108a2015-08-08 23:20:58 +0200818 current = (ALIGN(current, 64));
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200819 facs = (acpi_facs_t *) current;
820 current += sizeof(acpi_facs_t);
821 ALIGN_CURRENT;
822 acpi_create_facs(facs);
823
824 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
825 dsdt = (acpi_header_t *) current;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200826 memcpy(dsdt, dsdt_file, sizeof(acpi_header_t));
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200827 if (dsdt->length >= sizeof(acpi_header_t)) {
828 current += sizeof(acpi_header_t);
829
830 acpigen_set_current((char *) current);
831 for (dev = all_devices; dev; dev = dev->next)
832 if (dev->ops && dev->ops->acpi_inject_dsdt_generator) {
Alexander Couzensa90dad12015-04-12 21:49:46 +0200833 dev->ops->acpi_inject_dsdt_generator(dev);
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200834 }
835 current = (unsigned long) acpigen_get_current();
836 memcpy((char *)current,
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200837 (char *)dsdt_file + sizeof(acpi_header_t),
Vladimir Serbinenko334fd8e2014-10-05 11:10:35 +0200838 dsdt->length - sizeof(acpi_header_t));
839 current += dsdt->length - sizeof(acpi_header_t);
840
841 /* (Re)calculate length and checksum. */
842 dsdt->length = current - (unsigned long)dsdt;
843 dsdt->checksum = 0;
844 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
845 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200846
847 ALIGN_CURRENT;
848
849 printk(BIOS_DEBUG, "ACPI: * FADT\n");
850 fadt = (acpi_fadt_t *) current;
851 current += sizeof(acpi_fadt_t);
852 ALIGN_CURRENT;
853
854 acpi_create_fadt(fadt, facs, dsdt);
855 acpi_add_table(rsdp, fadt);
856
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100857 if (slic_file) {
858 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
859 slic = (acpi_header_t *)current;
860 memcpy(slic, slic_file, slic_file->length);
861 current += slic_file->length;
862 ALIGN_CURRENT;
863 acpi_add_table(rsdp, slic);
864 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200865
866 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
867 ssdt = (acpi_header_t *)current;
868 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
Vladimir Serbinenko9310df82014-10-10 20:40:41 +0200869 if (ssdt->length > sizeof(acpi_header_t)) {
870 current += ssdt->length;
871 acpi_add_table(rsdp, ssdt);
872 ALIGN_CURRENT;
873 }
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200874
875 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
876 mcfg = (acpi_mcfg_t *) current;
877 acpi_create_mcfg(mcfg);
878 if (mcfg->header.length > sizeof(acpi_mcfg_t)) {
879 current += mcfg->header.length;
880 ALIGN_CURRENT;
881 acpi_add_table(rsdp, mcfg);
882 }
883
Vladimir Serbinenkof44ac132015-05-20 19:52:01 +0200884 printk(BIOS_DEBUG, "ACPI: * TCPA\n");
885 tcpa = (acpi_tcpa_t *) current;
886 acpi_create_tcpa(tcpa);
887 if (tcpa->header.length >= sizeof(acpi_tcpa_t)) {
888 current += tcpa->header.length;
889 ALIGN_CURRENT;
890 acpi_add_table(rsdp, tcpa);
891 }
892
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200893 printk(BIOS_DEBUG, "ACPI: * MADT\n");
894
895 madt = (acpi_madt_t *) current;
896 acpi_create_madt(madt);
897 if (madt->header.length > sizeof(acpi_madt_t)) {
898 current+=madt->header.length;
899 acpi_add_table(rsdp,madt);
900 }
901 ALIGN_CURRENT;
902
903 printk(BIOS_DEBUG, "current = %lx\n", current);
904
905 for (dev = all_devices; dev; dev = dev->next) {
906 if (dev->ops && dev->ops->write_acpi_tables) {
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200907 current = dev->ops->write_acpi_tables(dev, current, rsdp);
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200908 ALIGN_CURRENT;
909 }
910 }
911
912 printk(BIOS_INFO, "ACPI: done.\n");
913 return current;
914}
Vladimir Serbinenko2d7bd8a2014-08-30 19:28:05 +0200915
Patrick Georgie1667822012-05-05 15:29:32 +0200916#if CONFIG_HAVE_ACPI_RESUME
Kyösti Mälkki134f5042014-12-26 13:29:09 +0200917void __attribute__((weak)) mainboard_suspend_resume(void)
918{
919}
920
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500921void acpi_resume(void *wake_vec)
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000922{
Duncan Laurie11290c42012-10-03 19:07:05 -0700923#if CONFIG_HAVE_SMI_HANDLER
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500924 u32 *gnvs_address = cbmem_find(CBMEM_ID_ACPI_GNVS_PTR);
Duncan Laurie11290c42012-10-03 19:07:05 -0700925
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500926 /* Restore GNVS pointer in SMM if found */
927 if (gnvs_address && *gnvs_address) {
928 printk(BIOS_DEBUG, "Restore GNVS pointer to 0x%08x\n",
929 *gnvs_address);
930 smm_setup_structures((void *)*gnvs_address, NULL, NULL);
Stefan Reinauercb91e152012-04-03 23:28:22 +0200931 }
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500932#endif
933
934 /* Call mainboard resume handler first, if defined. */
Kyösti Mälkki134f5042014-12-26 13:29:09 +0200935 mainboard_suspend_resume();
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500936
937 post_code(POST_OS_RESUME);
938 acpi_jump_to_wakeup(wake_vec);
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000939}
940
Kyösti Mälkki7a846e72015-01-09 23:55:09 +0200941/* This is filled with acpi_is_wakeup() call early in ramstage. */
942int acpi_slp_type = -1;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000943
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200944#if IS_ENABLED(CONFIG_EARLY_CBMEM_INIT)
945int acpi_get_sleep_type(void)
Kyösti Mälkki134f5042014-12-26 13:29:09 +0200946{
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200947 struct romstage_handoff *handoff;
948
949 handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO);
950
951 if (handoff == NULL) {
952 printk(BIOS_DEBUG, "Unknown boot method, assuming normal.\n");
953 return 0;
954 } else if (handoff->s3_resume) {
955 printk(BIOS_DEBUG, "S3 Resume.\n");
956 return 3;
957 } else {
958 printk(BIOS_DEBUG, "Normal boot.\n");
959 return 0;
960 }
Kyösti Mälkki134f5042014-12-26 13:29:09 +0200961}
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200962#endif
Kyösti Mälkki134f5042014-12-26 13:29:09 +0200963
Kyösti Mälkkidb8693b2014-06-19 23:29:07 +0300964static void acpi_handoff_wakeup(void)
965{
Kyösti Mälkki7a846e72015-01-09 23:55:09 +0200966 if (acpi_slp_type < 0)
967 acpi_slp_type = acpi_get_sleep_type();
Kyösti Mälkkidb8693b2014-06-19 23:29:07 +0300968}
969
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +0200970int acpi_is_wakeup(void)
Rudolf Marek33cafe52009-04-13 18:07:02 +0000971{
Kyösti Mälkkidb8693b2014-06-19 23:29:07 +0300972 acpi_handoff_wakeup();
Tobias Diedrich4e22a3b2010-12-13 22:39:46 +0100973 /* Both resume from S2 and resume from S3 restart at CPU reset */
974 return (acpi_slp_type == 3 || acpi_slp_type == 2);
Rudolf Marek33cafe52009-04-13 18:07:02 +0000975}
976
Kyösti Mälkki4d9b7722014-06-19 19:45:40 +0300977int acpi_is_wakeup_s3(void)
978{
Kyösti Mälkkidb8693b2014-06-19 23:29:07 +0300979 acpi_handoff_wakeup();
Kyösti Mälkki4d9b7722014-06-19 19:45:40 +0300980 return (acpi_slp_type == 3);
981}
982
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +0200983void acpi_fail_wakeup(void)
984{
985 if (acpi_slp_type == 3 || acpi_slp_type == 2)
986 acpi_slp_type = 0;
987}
988
Kyösti Mälkki7b14f082014-10-16 20:58:47 +0300989void acpi_prepare_resume_backup(void)
990{
991 if (!acpi_s3_resume_allowed())
992 return;
993
994 /* Let's prepare the ACPI S3 Resume area now already, so we can rely on
995 * it being there during reboot time. We don't need the pointer, nor
996 * the result right now. If it fails, ACPI resume will be disabled.
997 */
998
999 if (HIGH_MEMORY_SAVE)
1000 cbmem_add(CBMEM_ID_RESUME, HIGH_MEMORY_SAVE);
Kyösti Mälkki7b14f082014-10-16 20:58:47 +03001001}
1002
Rudolf Marek33cafe52009-04-13 18:07:02 +00001003static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
1004{
1005 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
1006 return NULL;
1007
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001008 printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001009
1010 if (acpi_checksum((void *)rsdp, 20) != 0)
1011 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001012 printk(BIOS_DEBUG, "Checksum 1 passed\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001013
1014 if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
1015 rsdp->length) != 0))
1016 return NULL;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001017 printk(BIOS_DEBUG, "Checksum 2 passed all OK\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001018
1019 return rsdp;
1020}
1021
1022static acpi_rsdp_t *rsdp;
1023
1024void *acpi_get_wakeup_rsdp(void)
1025{
1026 return rsdp;
1027}
1028
1029void *acpi_find_wakeup_vector(void)
1030{
1031 char *p, *end;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001032 acpi_rsdt_t *rsdt;
1033 acpi_facs_t *facs;
Martin Rothc5f49262012-12-14 19:17:55 -07001034 acpi_fadt_t *fadt = NULL;
Uwe Hermann622824c2010-11-19 15:14:42 +00001035 void *wake_vec;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001036 int i;
1037
1038 rsdp = NULL;
1039
1040 if (!acpi_is_wakeup())
1041 return NULL;
1042
Uwe Hermann622824c2010-11-19 15:14:42 +00001043 printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001044
Uwe Hermann622824c2010-11-19 15:14:42 +00001045 /* Find RSDP. */
1046 for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) {
1047 if ((rsdp = valid_rsdp((acpi_rsdp_t *)p)))
Rudolf Marek33cafe52009-04-13 18:07:02 +00001048 break;
1049 }
1050
1051 if (rsdp == NULL)
1052 return NULL;
1053
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001054 printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001055 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
Stefan Reinauer14e22772010-04-27 06:56:47 +00001056
Uwe Hermann622824c2010-11-19 15:14:42 +00001057 end = (char *)rsdt + rsdt->header.length;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001058 printk(BIOS_DEBUG, "RSDT found at %p ends at %p\n", rsdt, end);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001059
Uwe Hermann622824c2010-11-19 15:14:42 +00001060 for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
Stefan Reinauer71a30182015-07-30 16:28:13 -07001061 fadt = (acpi_fadt_t *)(uintptr_t)rsdt->entry[i];
Stefan Reinauercdfe3762009-07-21 22:15:43 +00001062 if (strncmp((char *)fadt, "FACP", 4) == 0)
Rudolf Marek33cafe52009-04-13 18:07:02 +00001063 break;
1064 fadt = NULL;
1065 }
1066
1067 if (fadt == NULL)
1068 return NULL;
1069
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001070 printk(BIOS_DEBUG, "FADT found at %p\n", fadt);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001071 facs = (acpi_facs_t *)(uintptr_t)fadt->firmware_ctrl;
Rudolf Marek33cafe52009-04-13 18:07:02 +00001072
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001073 if (facs == NULL) {
Uwe Hermann622824c2010-11-19 15:14:42 +00001074 printk(BIOS_DEBUG, "No FACS found, wake up from S3 not "
1075 "possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +00001076 return NULL;
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00001077 }
Rudolf Marek33cafe52009-04-13 18:07:02 +00001078
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001079 printk(BIOS_DEBUG, "FACS found at %p\n", facs);
Stefan Reinauer71a30182015-07-30 16:28:13 -07001080 wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001081 printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec);
Uwe Hermann622824c2010-11-19 15:14:42 +00001082
Rudolf Marek33cafe52009-04-13 18:07:02 +00001083 return wake_vec;
1084}
1085
Tobias Diedrich4e22a3b2010-12-13 22:39:46 +01001086#if CONFIG_SMP
Rudolf Marek33cafe52009-04-13 18:07:02 +00001087extern char *lowmem_backup;
1088extern char *lowmem_backup_ptr;
1089extern int lowmem_backup_size;
Tobias Diedrich4e22a3b2010-12-13 22:39:46 +01001090#endif
Rudolf Marek33cafe52009-04-13 18:07:02 +00001091
Uwe Hermann622824c2010-11-19 15:14:42 +00001092#define WAKEUP_BASE 0x600
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001093
Stefan Reinauer71a30182015-07-30 16:28:13 -07001094void (*acpi_do_wakeup)(uintptr_t vector, u32 backup_source, u32 backup_target,
Stefan Reinauer399486e2012-12-06 13:54:29 -08001095 u32 backup_size) asmlinkage = (void *)WAKEUP_BASE;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001096
Aaron Durbina146d582013-02-08 16:56:51 -06001097extern unsigned char __wakeup;
1098extern unsigned int __wakeup_size;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001099
Rudolf Marek33cafe52009-04-13 18:07:02 +00001100void acpi_jump_to_wakeup(void *vector)
1101{
Stefan Reinauer71a30182015-07-30 16:28:13 -07001102 uintptr_t acpi_backup_memory = 0;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001103
Kyösti Mälkki2ca2afe2014-06-17 15:41:37 +03001104 if (HIGH_MEMORY_SAVE && acpi_s3_resume_allowed()) {
Stefan Reinauer71a30182015-07-30 16:28:13 -07001105 acpi_backup_memory = (uintptr_t)cbmem_find(CBMEM_ID_RESUME);
Kyösti Mälkki2ca2afe2014-06-17 15:41:37 +03001106
1107 if (!acpi_backup_memory) {
1108 printk(BIOS_WARNING, "ACPI: Backup memory missing. "
1109 "No S3 resume.\n");
1110 return;
1111 }
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001112 }
1113
Tobias Diedrich4e22a3b2010-12-13 22:39:46 +01001114#if CONFIG_SMP
Martin Roth7b5f8ef2013-07-08 16:22:10 -06001115 // FIXME: This should go into the ACPI backup memory, too. No pork sausages.
Uwe Hermann622824c2010-11-19 15:14:42 +00001116 /*
1117 * Just restore the SMP trampoline and continue with wakeup on
1118 * assembly level.
1119 */
Rudolf Marek33cafe52009-04-13 18:07:02 +00001120 memcpy(lowmem_backup_ptr, lowmem_backup, lowmem_backup_size);
Tobias Diedrich4e22a3b2010-12-13 22:39:46 +01001121#endif
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001122
Uwe Hermann622824c2010-11-19 15:14:42 +00001123 /* Copy wakeup trampoline in place. */
Aaron Durbina146d582013-02-08 16:56:51 -06001124 memcpy((void *)WAKEUP_BASE, &__wakeup, __wakeup_size);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +00001125
Duncan Lauriecde78012011-10-19 15:32:39 -07001126 timestamp_add_now(TS_ACPI_WAKE_JUMP);
Duncan Lauriecde78012011-10-19 15:32:39 -07001127
Stefan Reinauer71a30182015-07-30 16:28:13 -07001128 acpi_do_wakeup((uintptr_t)vector, acpi_backup_memory, CONFIG_RAMBASE,
Uwe Hermann622824c2010-11-19 15:14:42 +00001129 HIGH_MEMORY_SAVE);
Rudolf Marek33cafe52009-04-13 18:07:02 +00001130}
1131#endif
Duncan Laurie11290c42012-10-03 19:07:05 -07001132
1133void acpi_save_gnvs(u32 gnvs_address)
1134{
Duncan Laurie9c07c8f2013-03-22 11:08:39 -07001135 u32 *gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS_PTR, sizeof(*gnvs));
Duncan Laurie11290c42012-10-03 19:07:05 -07001136 if (gnvs)
1137 *gnvs = gnvs_address;
1138}