Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 4 | * coreboot ACPI Table support |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 5 | * written by Stefan Reinauer <stepan@openbios.org> |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 6 | * |
| 7 | * Copyright (C) 2004 SUSE LINUX AG |
| 8 | * Copyright (C) 2005-2009 coresystems GmbH |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 9 | * |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 10 | * ACPI FADT, FACS, and DSDT table support added by |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 11 | * Nick Barker <nick.barker9@btinternet.com>, and those portions |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 12 | * Copyright (C) 2004 Nick Barker |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 13 | * |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 14 | * Copyright (C) 2005 ADVANCED MICRO DEVICES, INC. All Rights Reserved. |
Stefan Reinauer | d6edf7a | 2006-01-05 00:19:52 +0000 | [diff] [blame] | 15 | * 2005.9 yhlu add SRAT table generation |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 18 | /* |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 19 | * Each system port implementing ACPI has to provide two functions: |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 20 | * |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 21 | * write_acpi_tables() |
| 22 | * acpi_dump_apics() |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 23 | * |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 24 | * See Kontron 986LCD-M port for a good example of an ACPI implementation |
| 25 | * in coreboot. |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 26 | */ |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 27 | |
| 28 | #include <console/console.h> |
| 29 | #include <string.h> |
| 30 | #include <arch/acpi.h> |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 31 | #include <arch/acpigen.h> |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 32 | #include <device/pci.h> |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 33 | #include <cbmem.h> |
Patrick Georgi | c8feedd | 2012-02-16 18:43:25 +0100 | [diff] [blame] | 34 | #include <cpu/x86/lapic_def.h> |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 35 | #include <cpu/cpu.h> |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 36 | #include <cbfs.h> |
Duncan Laurie | cde7801 | 2011-10-19 15:32:39 -0700 | [diff] [blame] | 37 | #if CONFIG_COLLECT_TIMESTAMPS |
| 38 | #include <timestamp.h> |
| 39 | #endif |
Kyösti Mälkki | 9e94dbf | 2015-01-08 20:03:18 +0200 | [diff] [blame] | 40 | #include <romstage_handoff.h> |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 41 | |
Patrick Georgi | 9aeb694 | 2012-10-05 21:54:38 +0200 | [diff] [blame] | 42 | /* FIXME: Kconfig doesn't support overridable defaults :-( */ |
| 43 | #ifndef CONFIG_HPET_MIN_TICKS |
| 44 | #define CONFIG_HPET_MIN_TICKS 0x1000 |
| 45 | #endif |
| 46 | |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 47 | u8 acpi_checksum(u8 *table, u32 length) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 48 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 49 | u8 ret = 0; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 50 | while (length--) { |
| 51 | ret += *table; |
| 52 | table++; |
| 53 | } |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 54 | return -ret; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 57 | /** |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 58 | * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length |
| 59 | * and checksum. |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 60 | */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 61 | void acpi_add_table(acpi_rsdp_t *rsdp, void *table) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 62 | { |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 63 | int i, entries_num; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 64 | acpi_rsdt_t *rsdt; |
| 65 | acpi_xsdt_t *xsdt = NULL; |
| 66 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 67 | /* The RSDT is mandatory... */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 68 | rsdt = (acpi_rsdt_t *)rsdp->rsdt_address; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 69 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 70 | /* ...while the XSDT is not. */ |
| 71 | if (rsdp->xsdt_address) |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 72 | xsdt = (acpi_xsdt_t *)((u32)rsdp->xsdt_address); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 73 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 74 | /* This should always be MAX_ACPI_TABLES. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 75 | entries_num = ARRAY_SIZE(rsdt->entry); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 76 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 77 | for (i = 0; i < entries_num; i++) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 78 | if (rsdt->entry[i] == 0) |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 79 | break; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 82 | if (i >= entries_num) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 83 | printk(BIOS_ERR, "ACPI: Error: Could not add ACPI table, " |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 84 | "too many tables.\n"); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 85 | return; |
| 86 | } |
| 87 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 88 | /* Add table to the RSDT. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 89 | rsdt->entry[i] = (u32)table; |
| 90 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 91 | /* Fix RSDT length or the kernel will assume invalid entries. */ |
| 92 | rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i + 1)); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 93 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 94 | /* Re-calculate checksum. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 95 | rsdt->header.checksum = 0; /* Hope this won't get optimized away */ |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 96 | rsdt->header.checksum = acpi_checksum((u8 *)rsdt, rsdt->header.length); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 97 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 98 | /* |
| 99 | * And now the same thing for the XSDT. We use the same index as for |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 100 | * now we want the XSDT and RSDT to always be in sync in coreboot. |
| 101 | */ |
| 102 | if (xsdt) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 103 | /* Add table to the XSDT. */ |
| 104 | xsdt->entry[i] = (u64)(u32)table; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 105 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 106 | /* Fix XSDT length. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 107 | xsdt->header.length = sizeof(acpi_header_t) + |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 108 | (sizeof(u64) * (i + 1)); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 109 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 110 | /* Re-calculate checksum. */ |
| 111 | xsdt->header.checksum = 0; |
| 112 | xsdt->header.checksum = acpi_checksum((u8 *)xsdt, |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 113 | xsdt->header.length); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 116 | printk(BIOS_DEBUG, "ACPI: added table %d/%d, length now %d\n", |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 117 | i + 1, entries_num, rsdt->header.length); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 120 | int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base, |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 121 | u16 seg_nr, u8 start, u8 end) |
Stefan Reinauer | 26d431a | 2009-01-20 19:17:51 +0000 | [diff] [blame] | 122 | { |
Vladimir Serbinenko | 60fccdc | 2014-10-05 11:05:16 +0200 | [diff] [blame] | 123 | memset(mmconfig, 0, sizeof(*mmconfig)); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 124 | mmconfig->base_address = base; |
| 125 | mmconfig->base_reserved = 0; |
| 126 | mmconfig->pci_segment_group_number = seg_nr; |
| 127 | mmconfig->start_bus_number = start; |
| 128 | mmconfig->end_bus_number = end; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 129 | |
| 130 | return sizeof(acpi_mcfg_mmconfig_t); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 133 | int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 134 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 135 | lapic->type = 0; /* Local APIC structure */ |
| 136 | lapic->length = sizeof(acpi_madt_lapic_t); |
| 137 | lapic->flags = (1 << 0); /* Processor/LAPIC enabled */ |
| 138 | lapic->processor_id = cpu; |
| 139 | lapic->apic_id = apic; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 140 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 141 | return lapic->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 144 | unsigned long acpi_create_madt_lapics(unsigned long current) |
| 145 | { |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 146 | struct device *cpu; |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 147 | int index = 0; |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 148 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 149 | for (cpu = all_devices; cpu; cpu = cpu->next) { |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 150 | if ((cpu->path.type != DEVICE_PATH_APIC) || |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 151 | (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) { |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 152 | continue; |
| 153 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 154 | if (!cpu->enabled) |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 155 | continue; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 156 | current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 157 | index, cpu->path.apic.apic_id); |
| 158 | index++; |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 159 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 160 | |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 161 | return current; |
| 162 | } |
| 163 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 164 | int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr, |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 165 | u32 gsi_base) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 166 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 167 | ioapic->type = 1; /* I/O APIC structure */ |
| 168 | ioapic->length = sizeof(acpi_madt_ioapic_t); |
| 169 | ioapic->reserved = 0x00; |
| 170 | ioapic->gsi_base = gsi_base; |
| 171 | ioapic->ioapic_id = id; |
| 172 | ioapic->ioapic_addr = addr; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 173 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 174 | return ioapic->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 177 | int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride, |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 178 | u8 bus, u8 source, u32 gsirq, u16 flags) |
| 179 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 180 | irqoverride->type = 2; /* Interrupt source override */ |
| 181 | irqoverride->length = sizeof(acpi_madt_irqoverride_t); |
| 182 | irqoverride->bus = bus; |
| 183 | irqoverride->source = source; |
| 184 | irqoverride->gsirq = gsirq; |
| 185 | irqoverride->flags = flags; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 186 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 187 | return irqoverride->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 190 | int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu, |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 191 | u16 flags, u8 lint) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 192 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 193 | lapic_nmi->type = 4; /* Local APIC NMI structure */ |
| 194 | lapic_nmi->length = sizeof(acpi_madt_lapic_nmi_t); |
| 195 | lapic_nmi->flags = flags; |
| 196 | lapic_nmi->processor_id = cpu; |
| 197 | lapic_nmi->lint = lint; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 198 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 199 | return lapic_nmi->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 202 | void acpi_create_madt(acpi_madt_t *madt) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 203 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 204 | acpi_header_t *header = &(madt->header); |
| 205 | unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 206 | |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 207 | memset((void *)madt, 0, sizeof(acpi_madt_t)); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 208 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 209 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 210 | memcpy(header->signature, "APIC", 4); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 211 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 212 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 213 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 214 | |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 215 | header->length = sizeof(acpi_madt_t); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 216 | header->revision = 1; /* ACPI 1.0/2.0: 1, ACPI 3.0: 2, ACPI 4.0: 3 */ |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 217 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 218 | madt->lapic_addr = LOCAL_APIC_ADDR; |
| 219 | madt->flags = 0x1; /* PCAT_COMPAT */ |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 220 | |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 221 | current = acpi_fill_madt(current); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 222 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 223 | /* (Re)calculate length and checksum. */ |
| 224 | header->length = current - (unsigned long)madt; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 225 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 226 | header->checksum = acpi_checksum((void *)madt, header->length); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 229 | /* MCFG is defined in the PCI Firmware Specification 3.0. */ |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 230 | void acpi_create_mcfg(acpi_mcfg_t *mcfg) |
| 231 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 232 | acpi_header_t *header = &(mcfg->header); |
| 233 | unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 234 | |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 235 | memset((void *)mcfg, 0, sizeof(acpi_mcfg_t)); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 236 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 237 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 238 | memcpy(header->signature, "MCFG", 4); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 239 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 240 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 241 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 242 | |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 243 | header->length = sizeof(acpi_mcfg_t); |
| 244 | header->revision = 1; |
| 245 | |
| 246 | current = acpi_fill_mcfg(current); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 247 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 248 | /* (Re)calculate length and checksum. */ |
| 249 | header->length = current - (unsigned long)mcfg; |
| 250 | header->checksum = acpi_checksum((void *)mcfg, header->length); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 253 | static void *get_tcpa_log(u32 *size) |
| 254 | { |
| 255 | const struct cbmem_entry *ce; |
| 256 | const u32 tcpa_default_log_len = 0x10000; |
| 257 | void *lasa; |
| 258 | ce = cbmem_entry_find(CBMEM_ID_TCPA_LOG); |
| 259 | if (ce) { |
| 260 | lasa = cbmem_entry_start(ce); |
| 261 | *size = cbmem_entry_size(ce); |
| 262 | printk(BIOS_DEBUG, "TCPA log found at %p\n", lasa); |
| 263 | return lasa; |
| 264 | } |
| 265 | lasa = cbmem_add(CBMEM_ID_TCPA_LOG, tcpa_default_log_len); |
| 266 | if (!lasa) { |
| 267 | printk(BIOS_ERR, "TCPA log creation failed\n"); |
| 268 | return NULL; |
| 269 | } |
| 270 | |
| 271 | printk(BIOS_DEBUG, "TCPA log created at %p\n", lasa); |
| 272 | memset (lasa, 0, tcpa_default_log_len); |
| 273 | |
| 274 | *size = tcpa_default_log_len; |
| 275 | return lasa; |
| 276 | } |
| 277 | |
| 278 | static void acpi_create_tcpa(acpi_tcpa_t *tcpa) |
| 279 | { |
| 280 | acpi_header_t *header = &(tcpa->header); |
| 281 | u32 tcpa_log_len; |
| 282 | void *lasa; |
| 283 | |
| 284 | memset((void *)tcpa, 0, sizeof(acpi_tcpa_t)); |
| 285 | |
| 286 | lasa = get_tcpa_log(&tcpa_log_len); |
| 287 | if (!lasa) { |
| 288 | return; |
| 289 | } |
| 290 | |
| 291 | /* Fill out header fields. */ |
| 292 | memcpy(header->signature, "TCPA", 4); |
| 293 | memcpy(header->oem_id, OEM_ID, 6); |
| 294 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 295 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 296 | |
| 297 | header->length = sizeof(acpi_tcpa_t); |
| 298 | header->revision = 2; |
| 299 | |
| 300 | tcpa->platform_class = 0; |
| 301 | tcpa->laml = tcpa_log_len; |
| 302 | tcpa->lasa = (u32) lasa; |
| 303 | |
| 304 | /* Calculate checksum. */ |
| 305 | header->checksum = acpi_checksum((void *)tcpa, header->length); |
| 306 | } |
| 307 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 308 | void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 309 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 310 | unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t); |
| 311 | |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 312 | memset((void *)ssdt, 0, sizeof(acpi_header_t)); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 313 | |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 314 | memcpy(&ssdt->signature, "SSDT", 4); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 315 | ssdt->revision = 2; /* ACPI 1.0/2.0: ?, ACPI 3.0/4.0: 2 */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 316 | memcpy(&ssdt->oem_id, OEM_ID, 6); |
| 317 | memcpy(&ssdt->oem_table_id, oem_table_id, 8); |
| 318 | ssdt->oem_revision = 42; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 319 | memcpy(&ssdt->asl_compiler_id, ASLC, 4); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 320 | ssdt->asl_compiler_revision = 42; |
| 321 | ssdt->length = sizeof(acpi_header_t); |
| 322 | |
Stefan Reinauer | 8dcd50b | 2009-03-06 17:24:29 +0000 | [diff] [blame] | 323 | acpigen_set_current((char *) current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 324 | { |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 325 | struct device *dev; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 326 | for (dev = all_devices; dev; dev = dev->next) |
| 327 | if (dev->ops && dev->ops->acpi_fill_ssdt_generator) { |
Vladimir Serbinenko | 0a66991 | 2014-10-05 14:34:17 +0200 | [diff] [blame] | 328 | dev->ops->acpi_fill_ssdt_generator(); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 329 | } |
Vladimir Serbinenko | 0a66991 | 2014-10-05 14:34:17 +0200 | [diff] [blame] | 330 | current = (unsigned long) acpigen_get_current(); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 331 | } |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 332 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 333 | /* (Re)calculate length and checksum. */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 334 | ssdt->length = current - (unsigned long)ssdt; |
| 335 | ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length); |
| 336 | } |
| 337 | |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 338 | int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic) |
| 339 | { |
Myles Watson | 0b4c9f0 | 2009-03-10 18:06:47 +0000 | [diff] [blame] | 340 | memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t)); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 341 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 342 | lapic->type = 0; /* Processor local APIC/SAPIC affinity structure */ |
| 343 | lapic->length = sizeof(acpi_srat_lapic_t); |
| 344 | lapic->flags = (1 << 0); /* Enabled (the use of this structure). */ |
| 345 | lapic->proximity_domain_7_0 = node; |
| 346 | /* TODO: proximity_domain_31_8, local SAPIC EID, clock domain. */ |
| 347 | lapic->apic_id = apic; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 348 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 349 | return lapic->length; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 352 | int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek, |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 353 | u32 flags) |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 354 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 355 | mem->type = 1; /* Memory affinity structure */ |
| 356 | mem->length = sizeof(acpi_srat_mem_t); |
| 357 | mem->base_address_low = (basek << 10); |
| 358 | mem->base_address_high = (basek >> (32 - 10)); |
| 359 | mem->length_low = (sizek << 10); |
| 360 | mem->length_high = (sizek >> (32 - 10)); |
| 361 | mem->proximity_domain = node; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 362 | mem->flags = flags; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 363 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 364 | return mem->length; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 367 | /* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */ |
Vladimir Serbinenko | 5e59757 | 2014-10-11 23:45:40 +0200 | [diff] [blame] | 368 | void acpi_create_srat(acpi_srat_t *srat, |
| 369 | unsigned long (*acpi_fill_srat)(unsigned long current)) |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 370 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 371 | acpi_header_t *header = &(srat->header); |
| 372 | unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 373 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 374 | memset((void *)srat, 0, sizeof(acpi_srat_t)); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 375 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 376 | /* Fill out header fields. */ |
| 377 | memcpy(header->signature, "SRAT", 4); |
| 378 | memcpy(header->oem_id, OEM_ID, 6); |
| 379 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 380 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 381 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 382 | header->length = sizeof(acpi_srat_t); |
| 383 | header->revision = 1; /* ACPI 1.0: N/A, 2.0: 1, 3.0: 2, 4.0: 3 */ |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 384 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 385 | srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */ |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 386 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 387 | current = acpi_fill_srat(current); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 388 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 389 | /* (Re)calculate length and checksum. */ |
| 390 | header->length = current - (unsigned long)srat; |
| 391 | header->checksum = acpi_checksum((void *)srat, header->length); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Vladimir Serbinenko | 8d70e94 | 2014-11-09 13:22:27 +0100 | [diff] [blame] | 394 | void acpi_create_dmar(acpi_dmar_t *dmar, |
| 395 | unsigned long (*acpi_fill_dmar) (unsigned long)) |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 396 | { |
| 397 | acpi_header_t *header = &(dmar->header); |
| 398 | unsigned long current = (unsigned long)dmar + sizeof(acpi_dmar_t); |
| 399 | |
| 400 | memset((void *)dmar, 0, sizeof(acpi_dmar_t)); |
| 401 | |
| 402 | /* Fill out header fields. */ |
| 403 | memcpy(header->signature, "DMAR", 4); |
| 404 | memcpy(header->oem_id, OEM_ID, 6); |
| 405 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 406 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 407 | |
| 408 | header->length = sizeof(acpi_dmar_t); |
| 409 | header->revision = 1; |
| 410 | |
| 411 | dmar->host_address_width = 40 - 1; /* FIXME: == MTRR size? */ |
| 412 | dmar->flags = 0; |
| 413 | |
| 414 | current = acpi_fill_dmar(current); |
| 415 | |
| 416 | /* (Re)calculate length and checksum. */ |
| 417 | header->length = current - (unsigned long)dmar; |
| 418 | header->checksum = acpi_checksum((void *)dmar, header->length); |
| 419 | } |
| 420 | |
| 421 | unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags, |
| 422 | u16 segment, u32 bar) |
| 423 | { |
| 424 | dmar_entry_t *drhd = (dmar_entry_t *)current; |
| 425 | memset(drhd, 0, sizeof(*drhd)); |
| 426 | drhd->type = DMAR_DRHD; |
| 427 | drhd->length = sizeof(*drhd); /* will be fixed up later */ |
| 428 | drhd->flags = flags; |
| 429 | drhd->segment = segment; |
| 430 | drhd->bar = bar; |
| 431 | |
| 432 | return drhd->length; |
| 433 | } |
| 434 | |
| 435 | void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current) |
| 436 | { |
| 437 | dmar_entry_t *drhd = (dmar_entry_t *)base; |
| 438 | drhd->length = current - base; |
| 439 | } |
| 440 | |
| 441 | unsigned long acpi_create_dmar_drhd_ds_pci(unsigned long current, u8 segment, |
| 442 | u8 dev, u8 fn) |
| 443 | { |
| 444 | dev_scope_t *ds = (dev_scope_t *)current; |
| 445 | memset(ds, 0, sizeof(*ds)); |
| 446 | ds->type = SCOPE_PCI_ENDPOINT; |
| 447 | ds->length = sizeof(*ds) + 2; /* we don't support longer paths yet */ |
| 448 | ds->start_bus = segment; |
| 449 | ds->path[0].dev = dev; |
| 450 | ds->path[0].fn = fn; |
| 451 | |
| 452 | return ds->length; |
| 453 | } |
| 454 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 455 | /* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */ |
Vladimir Serbinenko | 5e59757 | 2014-10-11 23:45:40 +0200 | [diff] [blame] | 456 | void acpi_create_slit(acpi_slit_t *slit, |
| 457 | unsigned long (*acpi_fill_slit)(unsigned long current)) |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 458 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 459 | acpi_header_t *header = &(slit->header); |
| 460 | unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 461 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 462 | memset((void *)slit, 0, sizeof(acpi_slit_t)); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 463 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 464 | /* Fill out header fields. */ |
| 465 | memcpy(header->signature, "SLIT", 4); |
| 466 | memcpy(header->oem_id, OEM_ID, 6); |
| 467 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 468 | memcpy(header->asl_compiler_id, ASLC, 4); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 469 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 470 | header->length = sizeof(acpi_slit_t); |
| 471 | header->revision = 1; /* ACPI 1.0: N/A, ACPI 2.0/3.0/4.0: 1 */ |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 472 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 473 | current = acpi_fill_slit(current); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 474 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 475 | /* (Re)calculate length and checksum. */ |
| 476 | header->length = current - (unsigned long)slit; |
| 477 | header->checksum = acpi_checksum((void *)slit, header->length); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 480 | /* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */ |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 481 | void acpi_create_hpet(acpi_hpet_t *hpet) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 482 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 483 | acpi_header_t *header = &(hpet->header); |
| 484 | acpi_addr_t *addr = &(hpet->addr); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 485 | |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 486 | memset((void *)hpet, 0, sizeof(acpi_hpet_t)); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 487 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 488 | /* Fill out header fields. */ |
Stefan Reinauer | 4704dc5 | 2009-07-22 01:11:37 +0000 | [diff] [blame] | 489 | memcpy(header->signature, "HPET", 4); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 490 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 491 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 492 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 493 | |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 494 | header->length = sizeof(acpi_hpet_t); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 495 | header->revision = 1; /* Currently 1. Table added in ACPI 2.0. */ |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 496 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 497 | /* Fill out HPET address. */ |
| 498 | addr->space_id = 0; /* Memory */ |
| 499 | addr->bit_width = 64; |
| 500 | addr->bit_offset = 0; |
Patrick Georgi | 9aeb694 | 2012-10-05 21:54:38 +0200 | [diff] [blame] | 501 | addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff; |
| 502 | addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 503 | |
Patrick Georgi | 9aeb694 | 2012-10-05 21:54:38 +0200 | [diff] [blame] | 504 | hpet->id = *(unsigned int*)CONFIG_HPET_ADDRESS; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 505 | hpet->number = 0; |
Patrick Georgi | 9aeb694 | 2012-10-05 21:54:38 +0200 | [diff] [blame] | 506 | hpet->min_tick = CONFIG_HPET_MIN_TICKS; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 507 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 508 | header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 509 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 510 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 511 | unsigned long acpi_write_hpet(unsigned long current, acpi_rsdp_t *rsdp) |
| 512 | { |
| 513 | acpi_hpet_t *hpet; |
| 514 | |
| 515 | /* |
| 516 | * We explicitly add these tables later on: |
| 517 | */ |
| 518 | printk(BIOS_DEBUG, "ACPI: * HPET\n"); |
| 519 | |
| 520 | hpet = (acpi_hpet_t *) current; |
| 521 | current += sizeof(acpi_hpet_t); |
| 522 | current = ALIGN(current, 16); |
| 523 | acpi_create_hpet(hpet); |
| 524 | acpi_add_table(rsdp, hpet); |
| 525 | |
| 526 | return current; |
| 527 | } |
| 528 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 529 | void acpi_create_facs(acpi_facs_t *facs) |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 530 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 531 | memset((void *)facs, 0, sizeof(acpi_facs_t)); |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 532 | |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 533 | memcpy(facs->signature, "FACS", 4); |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 534 | facs->length = sizeof(acpi_facs_t); |
| 535 | facs->hardware_signature = 0; |
| 536 | facs->firmware_waking_vector = 0; |
| 537 | facs->global_lock = 0; |
| 538 | facs->flags = 0; |
| 539 | facs->x_firmware_waking_vector_l = 0; |
| 540 | facs->x_firmware_waking_vector_h = 0; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 541 | facs->version = 1; /* ACPI 1.0: 0, ACPI 2.0/3.0: 1, ACPI 4.0: 2 */ |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 542 | } |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 543 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 544 | static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id) |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 545 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 546 | acpi_header_t *header = &(rsdt->header); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 547 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 548 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 549 | memcpy(header->signature, "RSDT", 4); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 550 | memcpy(header->oem_id, oem_id, 6); |
| 551 | memcpy(header->oem_table_id, oem_table_id, 8); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 552 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 553 | |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 554 | header->length = sizeof(acpi_rsdt_t); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 555 | header->revision = 1; /* ACPI 1.0/2.0/3.0/4.0: 1 */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 556 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 557 | /* Entries are filled in later, we come with an empty set. */ |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 558 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 559 | /* Fix checksum. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 560 | header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 563 | static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id) |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 564 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 565 | acpi_header_t *header = &(xsdt->header); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 566 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 567 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 568 | memcpy(header->signature, "XSDT", 4); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 569 | memcpy(header->oem_id, oem_id, 6); |
| 570 | memcpy(header->oem_table_id, oem_table_id, 8); |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 571 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 572 | |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 573 | header->length = sizeof(acpi_xsdt_t); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 574 | header->revision = 1; /* ACPI 1.0: N/A, 2.0/3.0/4.0: 1 */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 575 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 576 | /* Entries are filled in later, we come with an empty set. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 577 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 578 | /* Fix checksum. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 579 | header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t)); |
| 580 | } |
| 581 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 582 | static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt, |
| 583 | acpi_xsdt_t *xsdt, char *oem_id) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 584 | { |
Stefan Reinauer | d18faac | 2009-11-05 18:06:43 +0000 | [diff] [blame] | 585 | memset(rsdp, 0, sizeof(acpi_rsdp_t)); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 586 | |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 587 | memcpy(rsdp->signature, RSDP_SIG, 8); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 588 | memcpy(rsdp->oem_id, oem_id, 6); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 589 | |
| 590 | rsdp->length = sizeof(acpi_rsdp_t); |
| 591 | rsdp->rsdt_address = (u32)rsdt; |
| 592 | |
| 593 | /* |
| 594 | * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2. |
| 595 | * |
| 596 | * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2. |
| 597 | * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR |
| 598 | * revision 0). |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 599 | */ |
| 600 | if (xsdt == NULL) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 601 | rsdp->revision = 0; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 602 | } else { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 603 | rsdp->xsdt_address = (u64)(u32)xsdt; |
| 604 | rsdp->revision = 2; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 605 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 606 | |
| 607 | /* Calculate checksums. */ |
| 608 | rsdp->checksum = acpi_checksum((void *)rsdp, 20); |
| 609 | rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 610 | } |
| 611 | |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 612 | unsigned long acpi_create_hest_error_source(acpi_hest_t *hest, acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len) |
| 613 | { |
| 614 | acpi_header_t *header = &(hest->header); |
| 615 | acpi_hest_hen_t *hen; |
| 616 | void *pos; |
| 617 | u16 len; |
| 618 | |
| 619 | pos = esd; |
| 620 | memset(pos, 0, sizeof(acpi_hest_esd_t)); |
| 621 | len = 0; |
| 622 | esd->type = type; /* MCE */ |
| 623 | esd->source_id = hest->error_source_count; |
| 624 | esd->flags = 0; /* FIRMWARE_FIRST */ |
| 625 | esd->enabled = 1; |
| 626 | esd->prealloc_erecords = 1; |
| 627 | esd->max_section_per_record = 0x1; |
| 628 | |
| 629 | len += sizeof(acpi_hest_esd_t); |
| 630 | pos = esd + 1; |
| 631 | |
| 632 | switch (type) { |
| 633 | case 0: /* MCE */ |
| 634 | break; |
| 635 | case 1: /* CMC */ |
| 636 | hen = (acpi_hest_hen_t *) (pos); |
| 637 | memset(pos, 0, sizeof(acpi_hest_hen_t)); |
| 638 | hen->type = 3; /* SCI? */ |
| 639 | hen->length = sizeof(acpi_hest_hen_t); |
| 640 | hen->conf_we = 0; /* Configuration Write Enable. */ |
| 641 | hen->poll_interval = 0; |
| 642 | hen->vector = 0; |
| 643 | hen->sw2poll_threshold_val = 0; |
| 644 | hen->sw2poll_threshold_win = 0; |
| 645 | hen->error_threshold_val = 0; |
| 646 | hen->error_threshold_win = 0; |
| 647 | len += sizeof(acpi_hest_hen_t); |
| 648 | pos = hen + 1; |
| 649 | break; |
| 650 | case 2: /* NMI */ |
| 651 | case 6: /* AER Root Port */ |
| 652 | case 7: /* AER Endpoint */ |
| 653 | case 8: /* AER Bridge */ |
| 654 | case 9: /* Generic Hardware Error Source. */ |
| 655 | /* TODO: */ |
| 656 | break; |
| 657 | default: |
| 658 | printk(BIOS_DEBUG, "Invalid type of Error Source."); |
| 659 | break; |
| 660 | } |
| 661 | hest->error_source_count ++; |
| 662 | |
| 663 | memcpy(pos, data, data_len); |
| 664 | len += data_len; |
| 665 | header->length += len; |
| 666 | |
| 667 | return len; |
| 668 | } |
| 669 | |
| 670 | /* ACPI 4.0 */ |
Vladimir Serbinenko | 807127f | 2014-11-09 13:36:18 +0100 | [diff] [blame] | 671 | void acpi_write_hest(acpi_hest_t *hest, |
| 672 | unsigned long (*acpi_fill_hest)(acpi_hest_t *hest)) |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 673 | { |
| 674 | acpi_header_t *header = &(hest->header); |
| 675 | |
| 676 | memset(hest, 0, sizeof(acpi_hest_t)); |
| 677 | |
| 678 | memcpy(header->signature, "HEST", 4); |
| 679 | memcpy(header->oem_id, OEM_ID, 6); |
| 680 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 681 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 682 | header->length += sizeof(acpi_hest_t); |
| 683 | header->revision = 1; |
| 684 | |
| 685 | acpi_fill_hest(hest); |
| 686 | |
| 687 | /* Calculate checksums. */ |
| 688 | header->checksum = acpi_checksum((void *)hest, header->length); |
| 689 | } |
| 690 | |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 691 | #if IS_ENABLED(CONFIG_COMMON_FADT) |
| 692 | void acpi_create_fadt(acpi_fadt_t *fadt,acpi_facs_t *facs, void *dsdt) |
| 693 | { |
| 694 | acpi_header_t *header = &(fadt->header); |
| 695 | |
| 696 | memset((void *) fadt, 0, sizeof(acpi_fadt_t)); |
| 697 | memcpy(header->signature, "FACP", 4); |
| 698 | header->length = sizeof(acpi_fadt_t); |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 699 | header->revision = 4; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 700 | memcpy(header->oem_id, OEM_ID, 6); |
| 701 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 702 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 703 | header->asl_compiler_revision = 0; |
| 704 | |
| 705 | fadt->firmware_ctrl = (unsigned long) facs; |
| 706 | fadt->dsdt = (unsigned long) dsdt; |
| 707 | |
| 708 | fadt->x_firmware_ctl_l = (unsigned long)facs; |
| 709 | fadt->x_firmware_ctl_h = 0; |
| 710 | fadt->x_dsdt_l = (unsigned long)dsdt; |
| 711 | fadt->x_dsdt_h = 0; |
| 712 | |
| 713 | if(IS_ENABLED(CONFIG_SYSTEM_TYPE_LAPTOP)) { |
| 714 | fadt->preferred_pm_profile = PM_MOBILE; |
| 715 | } else { |
| 716 | fadt->preferred_pm_profile = PM_DESKTOP; |
| 717 | } |
| 718 | |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 719 | acpi_fill_fadt(fadt); |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 720 | |
| 721 | header->checksum = |
| 722 | acpi_checksum((void *) fadt, header->length); |
| 723 | } |
| 724 | #endif |
| 725 | |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 726 | unsigned long __attribute__ ((weak)) fw_cfg_acpi_tables(unsigned long start) |
| 727 | { |
| 728 | return 0; |
| 729 | } |
| 730 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 731 | #define ALIGN_CURRENT current = (ALIGN(current, 16)) |
| 732 | unsigned long write_acpi_tables(unsigned long start) |
| 733 | { |
| 734 | unsigned long current; |
| 735 | acpi_rsdp_t *rsdp; |
| 736 | acpi_rsdt_t *rsdt; |
| 737 | acpi_xsdt_t *xsdt; |
| 738 | acpi_fadt_t *fadt; |
| 739 | acpi_facs_t *facs; |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 740 | acpi_header_t *slic_file, *slic; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 741 | acpi_header_t *ssdt; |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 742 | acpi_header_t *dsdt_file, *dsdt; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 743 | acpi_mcfg_t *mcfg; |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 744 | acpi_tcpa_t *tcpa; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 745 | acpi_madt_t *madt; |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 746 | struct device *dev; |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 747 | unsigned long fw; |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 748 | size_t slic_size, dsdt_size; |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 749 | char oem_id[6], oem_table_id[8]; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 750 | |
| 751 | current = start; |
| 752 | |
| 753 | /* Align ACPI tables to 16byte */ |
| 754 | ALIGN_CURRENT; |
| 755 | |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 756 | fw = fw_cfg_acpi_tables(current); |
| 757 | if (fw) |
| 758 | return fw; |
| 759 | |
Vladimir Serbinenko | a4cf83d | 2015-06-02 21:40:29 +0200 | [diff] [blame^] | 760 | dsdt_file = cbfs_boot_map_with_leak( |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 761 | CONFIG_CBFS_PREFIX "/dsdt.aml", |
| 762 | CBFS_TYPE_RAW, &dsdt_size); |
| 763 | if (!dsdt_file) { |
| 764 | printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n"); |
| 765 | return current; |
| 766 | } |
| 767 | |
| 768 | if (dsdt_file->length > dsdt_size |
| 769 | || dsdt_file->length < sizeof (acpi_header_t) |
| 770 | || memcmp(dsdt_file->signature, "DSDT", 4) != 0) { |
| 771 | printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n"); |
| 772 | return current; |
| 773 | } |
| 774 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 775 | slic_file = cbfs_boot_map_with_leak(CONFIG_CBFS_PREFIX "/slic", |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 776 | CBFS_TYPE_RAW, &slic_size); |
Vladimir Serbinenko | 2cb2978 | 2015-05-31 11:32:09 +0200 | [diff] [blame] | 777 | if (slic_file |
| 778 | && (slic_file->length > slic_size |
| 779 | || slic_file->length < sizeof (acpi_header_t) |
| 780 | || memcmp(slic_file->signature, "SLIC", 4) != 0)) { |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 781 | slic_file = 0; |
| 782 | } |
| 783 | |
| 784 | if (slic_file) { |
| 785 | memcpy(oem_id, slic_file->oem_id, 6); |
| 786 | memcpy(oem_table_id, slic_file->oem_table_id, 8); |
| 787 | } else { |
| 788 | memcpy(oem_id, OEM_ID, 6); |
| 789 | memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 790 | } |
| 791 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 792 | printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start); |
| 793 | |
| 794 | /* We need at least an RSDP and an RSDT Table */ |
| 795 | rsdp = (acpi_rsdp_t *) current; |
| 796 | current += sizeof(acpi_rsdp_t); |
| 797 | ALIGN_CURRENT; |
| 798 | rsdt = (acpi_rsdt_t *) current; |
| 799 | current += sizeof(acpi_rsdt_t); |
| 800 | ALIGN_CURRENT; |
| 801 | xsdt = (acpi_xsdt_t *) current; |
| 802 | current += sizeof(acpi_xsdt_t); |
| 803 | ALIGN_CURRENT; |
| 804 | |
| 805 | /* clear all table memory */ |
| 806 | memset((void *) start, 0, current - start); |
| 807 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 808 | acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id); |
| 809 | acpi_write_rsdt(rsdt, oem_id, oem_table_id); |
| 810 | acpi_write_xsdt(xsdt, oem_id, oem_table_id); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 811 | |
| 812 | printk(BIOS_DEBUG, "ACPI: * FACS\n"); |
| 813 | facs = (acpi_facs_t *) current; |
| 814 | current += sizeof(acpi_facs_t); |
| 815 | ALIGN_CURRENT; |
| 816 | acpi_create_facs(facs); |
| 817 | |
| 818 | printk(BIOS_DEBUG, "ACPI: * DSDT\n"); |
| 819 | dsdt = (acpi_header_t *) current; |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 820 | memcpy(dsdt, dsdt_file, sizeof(acpi_header_t)); |
Vladimir Serbinenko | 334fd8e | 2014-10-05 11:10:35 +0200 | [diff] [blame] | 821 | if (dsdt->length >= sizeof(acpi_header_t)) { |
| 822 | current += sizeof(acpi_header_t); |
| 823 | |
| 824 | acpigen_set_current((char *) current); |
| 825 | for (dev = all_devices; dev; dev = dev->next) |
| 826 | if (dev->ops && dev->ops->acpi_inject_dsdt_generator) { |
| 827 | dev->ops->acpi_inject_dsdt_generator(); |
| 828 | } |
| 829 | current = (unsigned long) acpigen_get_current(); |
| 830 | memcpy((char *)current, |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 831 | (char *)dsdt_file + sizeof(acpi_header_t), |
Vladimir Serbinenko | 334fd8e | 2014-10-05 11:10:35 +0200 | [diff] [blame] | 832 | dsdt->length - sizeof(acpi_header_t)); |
| 833 | current += dsdt->length - sizeof(acpi_header_t); |
| 834 | |
| 835 | /* (Re)calculate length and checksum. */ |
| 836 | dsdt->length = current - (unsigned long)dsdt; |
| 837 | dsdt->checksum = 0; |
| 838 | dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length); |
| 839 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 840 | |
| 841 | ALIGN_CURRENT; |
| 842 | |
| 843 | printk(BIOS_DEBUG, "ACPI: * FADT\n"); |
| 844 | fadt = (acpi_fadt_t *) current; |
| 845 | current += sizeof(acpi_fadt_t); |
| 846 | ALIGN_CURRENT; |
| 847 | |
| 848 | acpi_create_fadt(fadt, facs, dsdt); |
| 849 | acpi_add_table(rsdp, fadt); |
| 850 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 851 | if (slic_file) { |
| 852 | printk(BIOS_DEBUG, "ACPI: * SLIC\n"); |
| 853 | slic = (acpi_header_t *)current; |
| 854 | memcpy(slic, slic_file, slic_file->length); |
| 855 | current += slic_file->length; |
| 856 | ALIGN_CURRENT; |
| 857 | acpi_add_table(rsdp, slic); |
| 858 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 859 | |
| 860 | printk(BIOS_DEBUG, "ACPI: * SSDT\n"); |
| 861 | ssdt = (acpi_header_t *)current; |
| 862 | acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR); |
Vladimir Serbinenko | 9310df8 | 2014-10-10 20:40:41 +0200 | [diff] [blame] | 863 | if (ssdt->length > sizeof(acpi_header_t)) { |
| 864 | current += ssdt->length; |
| 865 | acpi_add_table(rsdp, ssdt); |
| 866 | ALIGN_CURRENT; |
| 867 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 868 | |
| 869 | printk(BIOS_DEBUG, "ACPI: * MCFG\n"); |
| 870 | mcfg = (acpi_mcfg_t *) current; |
| 871 | acpi_create_mcfg(mcfg); |
| 872 | if (mcfg->header.length > sizeof(acpi_mcfg_t)) { |
| 873 | current += mcfg->header.length; |
| 874 | ALIGN_CURRENT; |
| 875 | acpi_add_table(rsdp, mcfg); |
| 876 | } |
| 877 | |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 878 | printk(BIOS_DEBUG, "ACPI: * TCPA\n"); |
| 879 | tcpa = (acpi_tcpa_t *) current; |
| 880 | acpi_create_tcpa(tcpa); |
| 881 | if (tcpa->header.length >= sizeof(acpi_tcpa_t)) { |
| 882 | current += tcpa->header.length; |
| 883 | ALIGN_CURRENT; |
| 884 | acpi_add_table(rsdp, tcpa); |
| 885 | } |
| 886 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 887 | printk(BIOS_DEBUG, "ACPI: * MADT\n"); |
| 888 | |
| 889 | madt = (acpi_madt_t *) current; |
| 890 | acpi_create_madt(madt); |
| 891 | if (madt->header.length > sizeof(acpi_madt_t)) { |
| 892 | current+=madt->header.length; |
| 893 | acpi_add_table(rsdp,madt); |
| 894 | } |
| 895 | ALIGN_CURRENT; |
| 896 | |
| 897 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 898 | |
| 899 | for (dev = all_devices; dev; dev = dev->next) { |
| 900 | if (dev->ops && dev->ops->write_acpi_tables) { |
| 901 | current = dev->ops->write_acpi_tables(current, rsdp); |
| 902 | ALIGN_CURRENT; |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | printk(BIOS_INFO, "ACPI: done.\n"); |
| 907 | return current; |
| 908 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 909 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 910 | #if CONFIG_HAVE_ACPI_RESUME |
Kyösti Mälkki | 134f504 | 2014-12-26 13:29:09 +0200 | [diff] [blame] | 911 | void __attribute__((weak)) mainboard_suspend_resume(void) |
| 912 | { |
| 913 | } |
| 914 | |
Aaron Durbin | 0a6c20a | 2013-04-24 22:33:08 -0500 | [diff] [blame] | 915 | void acpi_resume(void *wake_vec) |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 916 | { |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 917 | #if CONFIG_HAVE_SMI_HANDLER |
Aaron Durbin | 0a6c20a | 2013-04-24 22:33:08 -0500 | [diff] [blame] | 918 | u32 *gnvs_address = cbmem_find(CBMEM_ID_ACPI_GNVS_PTR); |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 919 | |
Aaron Durbin | 0a6c20a | 2013-04-24 22:33:08 -0500 | [diff] [blame] | 920 | /* Restore GNVS pointer in SMM if found */ |
| 921 | if (gnvs_address && *gnvs_address) { |
| 922 | printk(BIOS_DEBUG, "Restore GNVS pointer to 0x%08x\n", |
| 923 | *gnvs_address); |
| 924 | smm_setup_structures((void *)*gnvs_address, NULL, NULL); |
Stefan Reinauer | cb91e15 | 2012-04-03 23:28:22 +0200 | [diff] [blame] | 925 | } |
Aaron Durbin | 0a6c20a | 2013-04-24 22:33:08 -0500 | [diff] [blame] | 926 | #endif |
| 927 | |
| 928 | /* Call mainboard resume handler first, if defined. */ |
Kyösti Mälkki | 134f504 | 2014-12-26 13:29:09 +0200 | [diff] [blame] | 929 | mainboard_suspend_resume(); |
Aaron Durbin | 0a6c20a | 2013-04-24 22:33:08 -0500 | [diff] [blame] | 930 | |
| 931 | post_code(POST_OS_RESUME); |
| 932 | acpi_jump_to_wakeup(wake_vec); |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Kyösti Mälkki | 7a846e7 | 2015-01-09 23:55:09 +0200 | [diff] [blame] | 935 | /* This is filled with acpi_is_wakeup() call early in ramstage. */ |
| 936 | int acpi_slp_type = -1; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 937 | |
Kyösti Mälkki | 9e94dbf | 2015-01-08 20:03:18 +0200 | [diff] [blame] | 938 | #if IS_ENABLED(CONFIG_EARLY_CBMEM_INIT) |
| 939 | int acpi_get_sleep_type(void) |
Kyösti Mälkki | 134f504 | 2014-12-26 13:29:09 +0200 | [diff] [blame] | 940 | { |
Kyösti Mälkki | 9e94dbf | 2015-01-08 20:03:18 +0200 | [diff] [blame] | 941 | struct romstage_handoff *handoff; |
| 942 | |
| 943 | handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO); |
| 944 | |
| 945 | if (handoff == NULL) { |
| 946 | printk(BIOS_DEBUG, "Unknown boot method, assuming normal.\n"); |
| 947 | return 0; |
| 948 | } else if (handoff->s3_resume) { |
| 949 | printk(BIOS_DEBUG, "S3 Resume.\n"); |
| 950 | return 3; |
| 951 | } else { |
| 952 | printk(BIOS_DEBUG, "Normal boot.\n"); |
| 953 | return 0; |
| 954 | } |
Kyösti Mälkki | 134f504 | 2014-12-26 13:29:09 +0200 | [diff] [blame] | 955 | } |
Kyösti Mälkki | 9e94dbf | 2015-01-08 20:03:18 +0200 | [diff] [blame] | 956 | #endif |
Kyösti Mälkki | 134f504 | 2014-12-26 13:29:09 +0200 | [diff] [blame] | 957 | |
Kyösti Mälkki | db8693b | 2014-06-19 23:29:07 +0300 | [diff] [blame] | 958 | static void acpi_handoff_wakeup(void) |
| 959 | { |
Kyösti Mälkki | 7a846e7 | 2015-01-09 23:55:09 +0200 | [diff] [blame] | 960 | if (acpi_slp_type < 0) |
| 961 | acpi_slp_type = acpi_get_sleep_type(); |
Kyösti Mälkki | db8693b | 2014-06-19 23:29:07 +0300 | [diff] [blame] | 962 | } |
| 963 | |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame] | 964 | int acpi_is_wakeup(void) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 965 | { |
Kyösti Mälkki | db8693b | 2014-06-19 23:29:07 +0300 | [diff] [blame] | 966 | acpi_handoff_wakeup(); |
Tobias Diedrich | 4e22a3b | 2010-12-13 22:39:46 +0100 | [diff] [blame] | 967 | /* Both resume from S2 and resume from S3 restart at CPU reset */ |
| 968 | return (acpi_slp_type == 3 || acpi_slp_type == 2); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Kyösti Mälkki | 4d9b772 | 2014-06-19 19:45:40 +0300 | [diff] [blame] | 971 | int acpi_is_wakeup_s3(void) |
| 972 | { |
Kyösti Mälkki | db8693b | 2014-06-19 23:29:07 +0300 | [diff] [blame] | 973 | acpi_handoff_wakeup(); |
Kyösti Mälkki | 4d9b772 | 2014-06-19 19:45:40 +0300 | [diff] [blame] | 974 | return (acpi_slp_type == 3); |
| 975 | } |
| 976 | |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame] | 977 | void acpi_fail_wakeup(void) |
| 978 | { |
| 979 | if (acpi_slp_type == 3 || acpi_slp_type == 2) |
| 980 | acpi_slp_type = 0; |
| 981 | } |
| 982 | |
Kyösti Mälkki | 7b14f08 | 2014-10-16 20:58:47 +0300 | [diff] [blame] | 983 | void acpi_prepare_resume_backup(void) |
| 984 | { |
| 985 | if (!acpi_s3_resume_allowed()) |
| 986 | return; |
| 987 | |
| 988 | /* Let's prepare the ACPI S3 Resume area now already, so we can rely on |
| 989 | * it being there during reboot time. We don't need the pointer, nor |
| 990 | * the result right now. If it fails, ACPI resume will be disabled. |
| 991 | */ |
| 992 | |
| 993 | if (HIGH_MEMORY_SAVE) |
| 994 | cbmem_add(CBMEM_ID_RESUME, HIGH_MEMORY_SAVE); |
Kyösti Mälkki | 7b14f08 | 2014-10-16 20:58:47 +0300 | [diff] [blame] | 995 | } |
| 996 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 997 | static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp) |
| 998 | { |
| 999 | if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0) |
| 1000 | return NULL; |
| 1001 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1002 | printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1003 | |
| 1004 | if (acpi_checksum((void *)rsdp, 20) != 0) |
| 1005 | return NULL; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1006 | printk(BIOS_DEBUG, "Checksum 1 passed\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1007 | |
| 1008 | if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp, |
| 1009 | rsdp->length) != 0)) |
| 1010 | return NULL; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1011 | printk(BIOS_DEBUG, "Checksum 2 passed all OK\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1012 | |
| 1013 | return rsdp; |
| 1014 | } |
| 1015 | |
| 1016 | static acpi_rsdp_t *rsdp; |
| 1017 | |
| 1018 | void *acpi_get_wakeup_rsdp(void) |
| 1019 | { |
| 1020 | return rsdp; |
| 1021 | } |
| 1022 | |
| 1023 | void *acpi_find_wakeup_vector(void) |
| 1024 | { |
| 1025 | char *p, *end; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1026 | acpi_rsdt_t *rsdt; |
| 1027 | acpi_facs_t *facs; |
Martin Roth | c5f4926 | 2012-12-14 19:17:55 -0700 | [diff] [blame] | 1028 | acpi_fadt_t *fadt = NULL; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1029 | void *wake_vec; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1030 | int i; |
| 1031 | |
| 1032 | rsdp = NULL; |
| 1033 | |
| 1034 | if (!acpi_is_wakeup()) |
| 1035 | return NULL; |
| 1036 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1037 | printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1038 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1039 | /* Find RSDP. */ |
| 1040 | for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) { |
| 1041 | if ((rsdp = valid_rsdp((acpi_rsdp_t *)p))) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1042 | break; |
| 1043 | } |
| 1044 | |
| 1045 | if (rsdp == NULL) |
| 1046 | return NULL; |
| 1047 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1048 | printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1049 | rsdt = (acpi_rsdt_t *) rsdp->rsdt_address; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 1050 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1051 | end = (char *)rsdt + rsdt->header.length; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1052 | printk(BIOS_DEBUG, "RSDT found at %p ends at %p\n", rsdt, end); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1053 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1054 | for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) { |
| 1055 | fadt = (acpi_fadt_t *)rsdt->entry[i]; |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 1056 | if (strncmp((char *)fadt, "FACP", 4) == 0) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1057 | break; |
| 1058 | fadt = NULL; |
| 1059 | } |
| 1060 | |
| 1061 | if (fadt == NULL) |
| 1062 | return NULL; |
| 1063 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1064 | printk(BIOS_DEBUG, "FADT found at %p\n", fadt); |
Stefan Reinauer | 69390db | 2009-05-26 12:33:52 +0000 | [diff] [blame] | 1065 | facs = (acpi_facs_t *)fadt->firmware_ctrl; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1066 | |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 1067 | if (facs == NULL) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1068 | printk(BIOS_DEBUG, "No FACS found, wake up from S3 not " |
| 1069 | "possible.\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1070 | return NULL; |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 1071 | } |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1072 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1073 | printk(BIOS_DEBUG, "FACS found at %p\n", facs); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1074 | wake_vec = (void *)facs->firmware_waking_vector; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1075 | printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1076 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1077 | return wake_vec; |
| 1078 | } |
| 1079 | |
Tobias Diedrich | 4e22a3b | 2010-12-13 22:39:46 +0100 | [diff] [blame] | 1080 | #if CONFIG_SMP |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1081 | extern char *lowmem_backup; |
| 1082 | extern char *lowmem_backup_ptr; |
| 1083 | extern int lowmem_backup_size; |
Tobias Diedrich | 4e22a3b | 2010-12-13 22:39:46 +0100 | [diff] [blame] | 1084 | #endif |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1085 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1086 | #define WAKEUP_BASE 0x600 |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 1087 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1088 | void (*acpi_do_wakeup)(u32 vector, u32 backup_source, u32 backup_target, |
Stefan Reinauer | 399486e | 2012-12-06 13:54:29 -0800 | [diff] [blame] | 1089 | u32 backup_size) asmlinkage = (void *)WAKEUP_BASE; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 1090 | |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 1091 | extern unsigned char __wakeup; |
| 1092 | extern unsigned int __wakeup_size; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 1093 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1094 | void acpi_jump_to_wakeup(void *vector) |
| 1095 | { |
Aaron Durbin | 8e4a355 | 2013-02-08 17:28:04 -0600 | [diff] [blame] | 1096 | u32 acpi_backup_memory = 0; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 1097 | |
Kyösti Mälkki | 2ca2afe | 2014-06-17 15:41:37 +0300 | [diff] [blame] | 1098 | if (HIGH_MEMORY_SAVE && acpi_s3_resume_allowed()) { |
| 1099 | acpi_backup_memory = (u32)cbmem_find(CBMEM_ID_RESUME); |
| 1100 | |
| 1101 | if (!acpi_backup_memory) { |
| 1102 | printk(BIOS_WARNING, "ACPI: Backup memory missing. " |
| 1103 | "No S3 resume.\n"); |
| 1104 | return; |
| 1105 | } |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
Tobias Diedrich | 4e22a3b | 2010-12-13 22:39:46 +0100 | [diff] [blame] | 1108 | #if CONFIG_SMP |
Martin Roth | 7b5f8ef | 2013-07-08 16:22:10 -0600 | [diff] [blame] | 1109 | // FIXME: This should go into the ACPI backup memory, too. No pork sausages. |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1110 | /* |
| 1111 | * Just restore the SMP trampoline and continue with wakeup on |
| 1112 | * assembly level. |
| 1113 | */ |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1114 | memcpy(lowmem_backup_ptr, lowmem_backup, lowmem_backup_size); |
Tobias Diedrich | 4e22a3b | 2010-12-13 22:39:46 +0100 | [diff] [blame] | 1115 | #endif |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 1116 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1117 | /* Copy wakeup trampoline in place. */ |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 1118 | memcpy((void *)WAKEUP_BASE, &__wakeup, __wakeup_size); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 1119 | |
Duncan Laurie | cde7801 | 2011-10-19 15:32:39 -0700 | [diff] [blame] | 1120 | #if CONFIG_COLLECT_TIMESTAMPS |
| 1121 | timestamp_add_now(TS_ACPI_WAKE_JUMP); |
| 1122 | #endif |
| 1123 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1124 | acpi_do_wakeup((u32)vector, acpi_backup_memory, CONFIG_RAMBASE, |
| 1125 | HIGH_MEMORY_SAVE); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1126 | } |
| 1127 | #endif |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 1128 | |
| 1129 | void acpi_save_gnvs(u32 gnvs_address) |
| 1130 | { |
Duncan Laurie | 9c07c8f | 2013-03-22 11:08:39 -0700 | [diff] [blame] | 1131 | u32 *gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS_PTR, sizeof(*gnvs)); |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 1132 | if (gnvs) |
| 1133 | *gnvs = gnvs_address; |
| 1134 | } |