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> |
Duncan Laurie | cde7801 | 2011-10-19 15:32:39 -0700 | [diff] [blame] | 36 | #if CONFIG_COLLECT_TIMESTAMPS |
| 37 | #include <timestamp.h> |
| 38 | #endif |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 39 | |
Patrick Georgi | 9aeb694 | 2012-10-05 21:54:38 +0200 | [diff] [blame] | 40 | /* 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. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 45 | u8 acpi_checksum(u8 *table, u32 length) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 46 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 47 | u8 ret = 0; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 48 | while (length--) { |
| 49 | ret += *table; |
| 50 | table++; |
| 51 | } |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 52 | return -ret; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 55 | /** |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 56 | * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length |
| 57 | * and checksum. |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 58 | */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 59 | void acpi_add_table(acpi_rsdp_t *rsdp, void *table) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 60 | { |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 61 | int i, entries_num; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 62 | acpi_rsdt_t *rsdt; |
| 63 | acpi_xsdt_t *xsdt = NULL; |
| 64 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 65 | /* The RSDT is mandatory... */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 66 | rsdt = (acpi_rsdt_t *)rsdp->rsdt_address; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 67 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 68 | /* ...while the XSDT is not. */ |
| 69 | if (rsdp->xsdt_address) |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 70 | xsdt = (acpi_xsdt_t *)((u32)rsdp->xsdt_address); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 71 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 72 | /* This should always be MAX_ACPI_TABLES. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 73 | entries_num = ARRAY_SIZE(rsdt->entry); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 74 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 75 | for (i = 0; i < entries_num; i++) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 76 | if (rsdt->entry[i] == 0) |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 77 | break; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 80 | if (i >= entries_num) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 81 | 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] | 82 | "too many tables.\n"); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 83 | return; |
| 84 | } |
| 85 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 86 | /* Add table to the RSDT. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 87 | rsdt->entry[i] = (u32)table; |
| 88 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 89 | /* Fix RSDT length or the kernel will assume invalid entries. */ |
| 90 | rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i + 1)); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 91 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 92 | /* Re-calculate checksum. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 93 | rsdt->header.checksum = 0; /* Hope this won't get optimized away */ |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 94 | rsdt->header.checksum = acpi_checksum((u8 *)rsdt, rsdt->header.length); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 95 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 96 | /* |
| 97 | * 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] | 98 | * now we want the XSDT and RSDT to always be in sync in coreboot. |
| 99 | */ |
| 100 | if (xsdt) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 101 | /* Add table to the XSDT. */ |
| 102 | xsdt->entry[i] = (u64)(u32)table; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 103 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 104 | /* Fix XSDT length. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 105 | xsdt->header.length = sizeof(acpi_header_t) + |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 106 | (sizeof(u64) * (i + 1)); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 107 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 108 | /* Re-calculate checksum. */ |
| 109 | xsdt->header.checksum = 0; |
| 110 | xsdt->header.checksum = acpi_checksum((u8 *)xsdt, |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 111 | xsdt->header.length); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 114 | 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] | 115 | i + 1, entries_num, rsdt->header.length); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 118 | 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] | 119 | u16 seg_nr, u8 start, u8 end) |
Stefan Reinauer | 26d431a | 2009-01-20 19:17:51 +0000 | [diff] [blame] | 120 | { |
Vladimir Serbinenko | 60fccdc | 2014-10-05 11:05:16 +0200 | [diff] [blame] | 121 | memset(mmconfig, 0, sizeof(*mmconfig)); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 122 | 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 Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 127 | |
| 128 | return sizeof(acpi_mcfg_mmconfig_t); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 131 | 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] | 132 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 133 | 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 Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 138 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 139 | return lapic->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 142 | unsigned long acpi_create_madt_lapics(unsigned long current) |
| 143 | { |
| 144 | device_t cpu; |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 145 | int index = 0; |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 146 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 147 | for (cpu = all_devices; cpu; cpu = cpu->next) { |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 148 | if ((cpu->path.type != DEVICE_PATH_APIC) || |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 149 | (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) { |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 150 | continue; |
| 151 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 152 | if (!cpu->enabled) |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 153 | continue; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 154 | current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 155 | index, cpu->path.apic.apic_id); |
| 156 | index++; |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 157 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 158 | |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 159 | return current; |
| 160 | } |
| 161 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 162 | 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] | 163 | u32 gsi_base) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 164 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 165 | 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 Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 171 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 172 | return ioapic->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 175 | int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride, |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 176 | u8 bus, u8 source, u32 gsirq, u16 flags) |
| 177 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 178 | 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 Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 184 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 185 | return irqoverride->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 188 | 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] | 189 | u16 flags, u8 lint) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 190 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 191 | 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 Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 196 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 197 | return lapic_nmi->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 200 | void acpi_create_madt(acpi_madt_t *madt) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 201 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 202 | acpi_header_t *header = &(madt->header); |
| 203 | unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 204 | |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 205 | memset((void *)madt, 0, sizeof(acpi_madt_t)); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 206 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 207 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 208 | memcpy(header->signature, "APIC", 4); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 209 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 210 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 211 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 212 | |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 213 | header->length = sizeof(acpi_madt_t); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 214 | 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] | 215 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 216 | madt->lapic_addr = LOCAL_APIC_ADDR; |
| 217 | madt->flags = 0x1; /* PCAT_COMPAT */ |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 218 | |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 219 | current = acpi_fill_madt(current); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 220 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 221 | /* (Re)calculate length and checksum. */ |
| 222 | header->length = current - (unsigned long)madt; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 223 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 224 | header->checksum = acpi_checksum((void *)madt, header->length); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 227 | /* MCFG is defined in the PCI Firmware Specification 3.0. */ |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 228 | void acpi_create_mcfg(acpi_mcfg_t *mcfg) |
| 229 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 230 | acpi_header_t *header = &(mcfg->header); |
| 231 | unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 232 | |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 233 | memset((void *)mcfg, 0, sizeof(acpi_mcfg_t)); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 234 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 235 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 236 | memcpy(header->signature, "MCFG", 4); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 237 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 238 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 239 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 240 | |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 241 | header->length = sizeof(acpi_mcfg_t); |
| 242 | header->revision = 1; |
| 243 | |
| 244 | current = acpi_fill_mcfg(current); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 245 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 246 | /* (Re)calculate length and checksum. */ |
| 247 | header->length = current - (unsigned long)mcfg; |
| 248 | header->checksum = acpi_checksum((void *)mcfg, header->length); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 249 | } |
| 250 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 251 | #if !IS_ENABLED(CONFIG_PER_DEVICE_ACPI_TABLES) |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 252 | /* |
Martin Roth | 7b5f8ef | 2013-07-08 16:22:10 -0600 | [diff] [blame] | 253 | * This can be overridden by platform ACPI setup code, if it calls |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 254 | * acpi_create_ssdt_generator(). |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 255 | */ |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 256 | unsigned long __attribute__((weak)) acpi_fill_ssdt_generator( |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 257 | unsigned long current, const char *oem_table_id) |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 258 | { |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 259 | return current; |
| 260 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 261 | #endif |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 262 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 263 | 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] | 264 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 265 | unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t); |
| 266 | |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 267 | memset((void *)ssdt, 0, sizeof(acpi_header_t)); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 268 | |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 269 | memcpy(&ssdt->signature, "SSDT", 4); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 270 | 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] | 271 | memcpy(&ssdt->oem_id, OEM_ID, 6); |
| 272 | memcpy(&ssdt->oem_table_id, oem_table_id, 8); |
| 273 | ssdt->oem_revision = 42; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 274 | memcpy(&ssdt->asl_compiler_id, ASLC, 4); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 275 | ssdt->asl_compiler_revision = 42; |
| 276 | ssdt->length = sizeof(acpi_header_t); |
| 277 | |
Stefan Reinauer | 8dcd50b | 2009-03-06 17:24:29 +0000 | [diff] [blame] | 278 | acpigen_set_current((char *) current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 279 | { |
| 280 | #if IS_ENABLED(CONFIG_PER_DEVICE_ACPI_TABLES) |
| 281 | device_t dev; |
| 282 | for (dev = all_devices; dev; dev = dev->next) |
| 283 | if (dev->ops && dev->ops->acpi_fill_ssdt_generator) { |
| 284 | current = dev->ops->acpi_fill_ssdt_generator(current, oem_table_id); |
| 285 | } |
| 286 | #else |
| 287 | current = acpi_fill_ssdt_generator(current, oem_table_id); |
| 288 | #endif |
| 289 | } |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 290 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 291 | /* (Re)calculate length and checksum. */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 292 | ssdt->length = current - (unsigned long)ssdt; |
| 293 | ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length); |
| 294 | } |
| 295 | |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 296 | int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic) |
| 297 | { |
Myles Watson | 0b4c9f0 | 2009-03-10 18:06:47 +0000 | [diff] [blame] | 298 | memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t)); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 299 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 300 | lapic->type = 0; /* Processor local APIC/SAPIC affinity structure */ |
| 301 | lapic->length = sizeof(acpi_srat_lapic_t); |
| 302 | lapic->flags = (1 << 0); /* Enabled (the use of this structure). */ |
| 303 | lapic->proximity_domain_7_0 = node; |
| 304 | /* TODO: proximity_domain_31_8, local SAPIC EID, clock domain. */ |
| 305 | lapic->apic_id = apic; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 306 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 307 | return lapic->length; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 310 | 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] | 311 | u32 flags) |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 312 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 313 | mem->type = 1; /* Memory affinity structure */ |
| 314 | mem->length = sizeof(acpi_srat_mem_t); |
| 315 | mem->base_address_low = (basek << 10); |
| 316 | mem->base_address_high = (basek >> (32 - 10)); |
| 317 | mem->length_low = (sizek << 10); |
| 318 | mem->length_high = (sizek >> (32 - 10)); |
| 319 | mem->proximity_domain = node; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 320 | mem->flags = flags; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 321 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 322 | return mem->length; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 325 | /* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */ |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 326 | void acpi_create_srat(acpi_srat_t *srat) |
| 327 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 328 | acpi_header_t *header = &(srat->header); |
| 329 | unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 330 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 331 | memset((void *)srat, 0, sizeof(acpi_srat_t)); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 332 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 333 | /* Fill out header fields. */ |
| 334 | memcpy(header->signature, "SRAT", 4); |
| 335 | memcpy(header->oem_id, OEM_ID, 6); |
| 336 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 337 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 338 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 339 | header->length = sizeof(acpi_srat_t); |
| 340 | 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] | 341 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 342 | srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */ |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 343 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 344 | current = acpi_fill_srat(current); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 345 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 346 | /* (Re)calculate length and checksum. */ |
| 347 | header->length = current - (unsigned long)srat; |
| 348 | header->checksum = acpi_checksum((void *)srat, header->length); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 351 | unsigned long __attribute__((weak)) acpi_fill_dmar(unsigned long current) |
| 352 | { |
| 353 | return current; |
| 354 | } |
| 355 | |
| 356 | void acpi_create_dmar(acpi_dmar_t *dmar) |
| 357 | { |
| 358 | acpi_header_t *header = &(dmar->header); |
| 359 | unsigned long current = (unsigned long)dmar + sizeof(acpi_dmar_t); |
| 360 | |
| 361 | memset((void *)dmar, 0, sizeof(acpi_dmar_t)); |
| 362 | |
| 363 | /* Fill out header fields. */ |
| 364 | memcpy(header->signature, "DMAR", 4); |
| 365 | memcpy(header->oem_id, OEM_ID, 6); |
| 366 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 367 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 368 | |
| 369 | header->length = sizeof(acpi_dmar_t); |
| 370 | header->revision = 1; |
| 371 | |
| 372 | dmar->host_address_width = 40 - 1; /* FIXME: == MTRR size? */ |
| 373 | dmar->flags = 0; |
| 374 | |
| 375 | current = acpi_fill_dmar(current); |
| 376 | |
| 377 | /* (Re)calculate length and checksum. */ |
| 378 | header->length = current - (unsigned long)dmar; |
| 379 | header->checksum = acpi_checksum((void *)dmar, header->length); |
| 380 | } |
| 381 | |
| 382 | unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags, |
| 383 | u16 segment, u32 bar) |
| 384 | { |
| 385 | dmar_entry_t *drhd = (dmar_entry_t *)current; |
| 386 | memset(drhd, 0, sizeof(*drhd)); |
| 387 | drhd->type = DMAR_DRHD; |
| 388 | drhd->length = sizeof(*drhd); /* will be fixed up later */ |
| 389 | drhd->flags = flags; |
| 390 | drhd->segment = segment; |
| 391 | drhd->bar = bar; |
| 392 | |
| 393 | return drhd->length; |
| 394 | } |
| 395 | |
| 396 | void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current) |
| 397 | { |
| 398 | dmar_entry_t *drhd = (dmar_entry_t *)base; |
| 399 | drhd->length = current - base; |
| 400 | } |
| 401 | |
| 402 | unsigned long acpi_create_dmar_drhd_ds_pci(unsigned long current, u8 segment, |
| 403 | u8 dev, u8 fn) |
| 404 | { |
| 405 | dev_scope_t *ds = (dev_scope_t *)current; |
| 406 | memset(ds, 0, sizeof(*ds)); |
| 407 | ds->type = SCOPE_PCI_ENDPOINT; |
| 408 | ds->length = sizeof(*ds) + 2; /* we don't support longer paths yet */ |
| 409 | ds->start_bus = segment; |
| 410 | ds->path[0].dev = dev; |
| 411 | ds->path[0].fn = fn; |
| 412 | |
| 413 | return ds->length; |
| 414 | } |
| 415 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 416 | /* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */ |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 417 | void acpi_create_slit(acpi_slit_t *slit) |
| 418 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 419 | acpi_header_t *header = &(slit->header); |
| 420 | unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 421 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 422 | memset((void *)slit, 0, sizeof(acpi_slit_t)); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 423 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 424 | /* Fill out header fields. */ |
| 425 | memcpy(header->signature, "SLIT", 4); |
| 426 | memcpy(header->oem_id, OEM_ID, 6); |
| 427 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 428 | memcpy(header->asl_compiler_id, ASLC, 4); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 429 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 430 | header->length = sizeof(acpi_slit_t); |
| 431 | 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] | 432 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 433 | current = acpi_fill_slit(current); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 434 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 435 | /* (Re)calculate length and checksum. */ |
| 436 | header->length = current - (unsigned long)slit; |
| 437 | header->checksum = acpi_checksum((void *)slit, header->length); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 440 | /* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */ |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 441 | void acpi_create_hpet(acpi_hpet_t *hpet) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 442 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 443 | acpi_header_t *header = &(hpet->header); |
| 444 | acpi_addr_t *addr = &(hpet->addr); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 445 | |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 446 | memset((void *)hpet, 0, sizeof(acpi_hpet_t)); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 447 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 448 | /* Fill out header fields. */ |
Stefan Reinauer | 4704dc5 | 2009-07-22 01:11:37 +0000 | [diff] [blame] | 449 | memcpy(header->signature, "HPET", 4); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 450 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 451 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 452 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 453 | |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 454 | header->length = sizeof(acpi_hpet_t); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 455 | header->revision = 1; /* Currently 1. Table added in ACPI 2.0. */ |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 456 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 457 | /* Fill out HPET address. */ |
| 458 | addr->space_id = 0; /* Memory */ |
| 459 | addr->bit_width = 64; |
| 460 | addr->bit_offset = 0; |
Patrick Georgi | 9aeb694 | 2012-10-05 21:54:38 +0200 | [diff] [blame] | 461 | addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff; |
| 462 | addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 463 | |
Patrick Georgi | 9aeb694 | 2012-10-05 21:54:38 +0200 | [diff] [blame] | 464 | hpet->id = *(unsigned int*)CONFIG_HPET_ADDRESS; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 465 | hpet->number = 0; |
Patrick Georgi | 9aeb694 | 2012-10-05 21:54:38 +0200 | [diff] [blame] | 466 | hpet->min_tick = CONFIG_HPET_MIN_TICKS; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 467 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 468 | header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 469 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 470 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 471 | unsigned long acpi_write_hpet(unsigned long current, acpi_rsdp_t *rsdp) |
| 472 | { |
| 473 | acpi_hpet_t *hpet; |
| 474 | |
| 475 | /* |
| 476 | * We explicitly add these tables later on: |
| 477 | */ |
| 478 | printk(BIOS_DEBUG, "ACPI: * HPET\n"); |
| 479 | |
| 480 | hpet = (acpi_hpet_t *) current; |
| 481 | current += sizeof(acpi_hpet_t); |
| 482 | current = ALIGN(current, 16); |
| 483 | acpi_create_hpet(hpet); |
| 484 | acpi_add_table(rsdp, hpet); |
| 485 | |
| 486 | return current; |
| 487 | } |
| 488 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 489 | void acpi_create_facs(acpi_facs_t *facs) |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 490 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 491 | memset((void *)facs, 0, sizeof(acpi_facs_t)); |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 492 | |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 493 | memcpy(facs->signature, "FACS", 4); |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 494 | facs->length = sizeof(acpi_facs_t); |
| 495 | facs->hardware_signature = 0; |
| 496 | facs->firmware_waking_vector = 0; |
| 497 | facs->global_lock = 0; |
| 498 | facs->flags = 0; |
| 499 | facs->x_firmware_waking_vector_l = 0; |
| 500 | facs->x_firmware_waking_vector_h = 0; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 501 | 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] | 502 | } |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 503 | |
| 504 | void acpi_write_rsdt(acpi_rsdt_t *rsdt) |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 505 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 506 | acpi_header_t *header = &(rsdt->header); |
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 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 509 | memcpy(header->signature, "RSDT", 4); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 510 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 511 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 512 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 513 | |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 514 | header->length = sizeof(acpi_rsdt_t); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 515 | 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] | 516 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 517 | /* Entries are filled in later, we come with an empty set. */ |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 518 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 519 | /* Fix checksum. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 520 | header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 523 | void acpi_write_xsdt(acpi_xsdt_t *xsdt) |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 524 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 525 | acpi_header_t *header = &(xsdt->header); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 526 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 527 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 528 | memcpy(header->signature, "XSDT", 4); |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 529 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 530 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 531 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 532 | |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 533 | header->length = sizeof(acpi_xsdt_t); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 534 | 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] | 535 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 536 | /* Entries are filled in later, we come with an empty set. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 537 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 538 | /* Fix checksum. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 539 | header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t)); |
| 540 | } |
| 541 | |
| 542 | void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt, acpi_xsdt_t *xsdt) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 543 | { |
Stefan Reinauer | d18faac | 2009-11-05 18:06:43 +0000 | [diff] [blame] | 544 | memset(rsdp, 0, sizeof(acpi_rsdp_t)); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 545 | |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 546 | memcpy(rsdp->signature, RSDP_SIG, 8); |
| 547 | memcpy(rsdp->oem_id, OEM_ID, 6); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 548 | |
| 549 | rsdp->length = sizeof(acpi_rsdp_t); |
| 550 | rsdp->rsdt_address = (u32)rsdt; |
| 551 | |
| 552 | /* |
| 553 | * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2. |
| 554 | * |
| 555 | * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2. |
| 556 | * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR |
| 557 | * revision 0). |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 558 | */ |
| 559 | if (xsdt == NULL) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 560 | rsdp->revision = 0; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 561 | } else { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 562 | rsdp->xsdt_address = (u64)(u32)xsdt; |
| 563 | rsdp->revision = 2; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 564 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 565 | |
| 566 | /* Calculate checksums. */ |
| 567 | rsdp->checksum = acpi_checksum((void *)rsdp, 20); |
| 568 | rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 569 | } |
| 570 | |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 571 | unsigned long __attribute__((weak)) acpi_fill_hest(acpi_hest_t *hest) |
| 572 | { |
| 573 | return (unsigned long)hest; |
| 574 | } |
| 575 | |
| 576 | unsigned long acpi_create_hest_error_source(acpi_hest_t *hest, acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len) |
| 577 | { |
| 578 | acpi_header_t *header = &(hest->header); |
| 579 | acpi_hest_hen_t *hen; |
| 580 | void *pos; |
| 581 | u16 len; |
| 582 | |
| 583 | pos = esd; |
| 584 | memset(pos, 0, sizeof(acpi_hest_esd_t)); |
| 585 | len = 0; |
| 586 | esd->type = type; /* MCE */ |
| 587 | esd->source_id = hest->error_source_count; |
| 588 | esd->flags = 0; /* FIRMWARE_FIRST */ |
| 589 | esd->enabled = 1; |
| 590 | esd->prealloc_erecords = 1; |
| 591 | esd->max_section_per_record = 0x1; |
| 592 | |
| 593 | len += sizeof(acpi_hest_esd_t); |
| 594 | pos = esd + 1; |
| 595 | |
| 596 | switch (type) { |
| 597 | case 0: /* MCE */ |
| 598 | break; |
| 599 | case 1: /* CMC */ |
| 600 | hen = (acpi_hest_hen_t *) (pos); |
| 601 | memset(pos, 0, sizeof(acpi_hest_hen_t)); |
| 602 | hen->type = 3; /* SCI? */ |
| 603 | hen->length = sizeof(acpi_hest_hen_t); |
| 604 | hen->conf_we = 0; /* Configuration Write Enable. */ |
| 605 | hen->poll_interval = 0; |
| 606 | hen->vector = 0; |
| 607 | hen->sw2poll_threshold_val = 0; |
| 608 | hen->sw2poll_threshold_win = 0; |
| 609 | hen->error_threshold_val = 0; |
| 610 | hen->error_threshold_win = 0; |
| 611 | len += sizeof(acpi_hest_hen_t); |
| 612 | pos = hen + 1; |
| 613 | break; |
| 614 | case 2: /* NMI */ |
| 615 | case 6: /* AER Root Port */ |
| 616 | case 7: /* AER Endpoint */ |
| 617 | case 8: /* AER Bridge */ |
| 618 | case 9: /* Generic Hardware Error Source. */ |
| 619 | /* TODO: */ |
| 620 | break; |
| 621 | default: |
| 622 | printk(BIOS_DEBUG, "Invalid type of Error Source."); |
| 623 | break; |
| 624 | } |
| 625 | hest->error_source_count ++; |
| 626 | |
| 627 | memcpy(pos, data, data_len); |
| 628 | len += data_len; |
| 629 | header->length += len; |
| 630 | |
| 631 | return len; |
| 632 | } |
| 633 | |
| 634 | /* ACPI 4.0 */ |
| 635 | void acpi_write_hest(acpi_hest_t *hest) |
| 636 | { |
| 637 | acpi_header_t *header = &(hest->header); |
| 638 | |
| 639 | memset(hest, 0, sizeof(acpi_hest_t)); |
| 640 | |
| 641 | memcpy(header->signature, "HEST", 4); |
| 642 | memcpy(header->oem_id, OEM_ID, 6); |
| 643 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 644 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 645 | header->length += sizeof(acpi_hest_t); |
| 646 | header->revision = 1; |
| 647 | |
| 648 | acpi_fill_hest(hest); |
| 649 | |
| 650 | /* Calculate checksums. */ |
| 651 | header->checksum = acpi_checksum((void *)hest, header->length); |
| 652 | } |
| 653 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 654 | #if IS_ENABLED(CONFIG_PER_DEVICE_ACPI_TABLES) |
| 655 | |
| 656 | extern const unsigned char AmlCode[]; |
| 657 | |
| 658 | #define ALIGN_CURRENT current = (ALIGN(current, 16)) |
| 659 | unsigned long write_acpi_tables(unsigned long start) |
| 660 | { |
| 661 | unsigned long current; |
| 662 | acpi_rsdp_t *rsdp; |
| 663 | acpi_rsdt_t *rsdt; |
| 664 | acpi_xsdt_t *xsdt; |
| 665 | acpi_fadt_t *fadt; |
| 666 | acpi_facs_t *facs; |
| 667 | #if CONFIG_HAVE_ACPI_SLIC |
| 668 | acpi_header_t *slic; |
| 669 | #endif |
| 670 | acpi_header_t *ssdt; |
| 671 | acpi_header_t *dsdt; |
| 672 | acpi_mcfg_t *mcfg; |
| 673 | acpi_madt_t *madt; |
| 674 | device_t dev; |
| 675 | |
| 676 | current = start; |
| 677 | |
| 678 | /* Align ACPI tables to 16byte */ |
| 679 | ALIGN_CURRENT; |
| 680 | |
| 681 | printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start); |
| 682 | |
| 683 | /* We need at least an RSDP and an RSDT Table */ |
| 684 | rsdp = (acpi_rsdp_t *) current; |
| 685 | current += sizeof(acpi_rsdp_t); |
| 686 | ALIGN_CURRENT; |
| 687 | rsdt = (acpi_rsdt_t *) current; |
| 688 | current += sizeof(acpi_rsdt_t); |
| 689 | ALIGN_CURRENT; |
| 690 | xsdt = (acpi_xsdt_t *) current; |
| 691 | current += sizeof(acpi_xsdt_t); |
| 692 | ALIGN_CURRENT; |
| 693 | |
| 694 | /* clear all table memory */ |
| 695 | memset((void *) start, 0, current - start); |
| 696 | |
| 697 | acpi_write_rsdp(rsdp, rsdt, xsdt); |
| 698 | acpi_write_rsdt(rsdt); |
| 699 | acpi_write_xsdt(xsdt); |
| 700 | |
| 701 | printk(BIOS_DEBUG, "ACPI: * FACS\n"); |
| 702 | facs = (acpi_facs_t *) current; |
| 703 | current += sizeof(acpi_facs_t); |
| 704 | ALIGN_CURRENT; |
| 705 | acpi_create_facs(facs); |
| 706 | |
| 707 | printk(BIOS_DEBUG, "ACPI: * DSDT\n"); |
| 708 | dsdt = (acpi_header_t *) current; |
| 709 | memcpy(dsdt, &AmlCode, sizeof(acpi_header_t)); |
| 710 | current += dsdt->length; |
| 711 | memcpy(dsdt, &AmlCode, dsdt->length); |
| 712 | |
| 713 | ALIGN_CURRENT; |
| 714 | |
| 715 | printk(BIOS_DEBUG, "ACPI: * FADT\n"); |
| 716 | fadt = (acpi_fadt_t *) current; |
| 717 | current += sizeof(acpi_fadt_t); |
| 718 | ALIGN_CURRENT; |
| 719 | |
| 720 | acpi_create_fadt(fadt, facs, dsdt); |
| 721 | acpi_add_table(rsdp, fadt); |
| 722 | |
| 723 | #if CONFIG_HAVE_ACPI_SLIC |
| 724 | printk(BIOS_DEBUG, "ACPI: * SLIC\n"); |
| 725 | slic = (acpi_header_t *)current; |
| 726 | current += acpi_create_slic(current); |
| 727 | ALIGN_CURRENT; |
| 728 | acpi_add_table(rsdp, slic); |
| 729 | #endif |
| 730 | |
| 731 | printk(BIOS_DEBUG, "ACPI: * SSDT\n"); |
| 732 | ssdt = (acpi_header_t *)current; |
| 733 | acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR); |
| 734 | current += ssdt->length; |
| 735 | acpi_add_table(rsdp, ssdt); |
| 736 | ALIGN_CURRENT; |
| 737 | |
| 738 | printk(BIOS_DEBUG, "ACPI: * MCFG\n"); |
| 739 | mcfg = (acpi_mcfg_t *) current; |
| 740 | acpi_create_mcfg(mcfg); |
| 741 | if (mcfg->header.length > sizeof(acpi_mcfg_t)) { |
| 742 | current += mcfg->header.length; |
| 743 | ALIGN_CURRENT; |
| 744 | acpi_add_table(rsdp, mcfg); |
| 745 | } |
| 746 | |
| 747 | printk(BIOS_DEBUG, "ACPI: * MADT\n"); |
| 748 | |
| 749 | madt = (acpi_madt_t *) current; |
| 750 | acpi_create_madt(madt); |
| 751 | if (madt->header.length > sizeof(acpi_madt_t)) { |
| 752 | current+=madt->header.length; |
| 753 | acpi_add_table(rsdp,madt); |
| 754 | } |
| 755 | ALIGN_CURRENT; |
| 756 | |
| 757 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 758 | |
| 759 | for (dev = all_devices; dev; dev = dev->next) { |
| 760 | if (dev->ops && dev->ops->write_acpi_tables) { |
| 761 | current = dev->ops->write_acpi_tables(current, rsdp); |
| 762 | ALIGN_CURRENT; |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | printk(BIOS_INFO, "ACPI: done.\n"); |
| 767 | return current; |
| 768 | } |
| 769 | #endif |
| 770 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 771 | #if CONFIG_HAVE_ACPI_RESUME |
Aaron Durbin | 0a6c20a | 2013-04-24 22:33:08 -0500 | [diff] [blame] | 772 | void acpi_resume(void *wake_vec) |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 773 | { |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 774 | #if CONFIG_HAVE_SMI_HANDLER |
Aaron Durbin | 0a6c20a | 2013-04-24 22:33:08 -0500 | [diff] [blame] | 775 | u32 *gnvs_address = cbmem_find(CBMEM_ID_ACPI_GNVS_PTR); |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 776 | |
Aaron Durbin | 0a6c20a | 2013-04-24 22:33:08 -0500 | [diff] [blame] | 777 | /* Restore GNVS pointer in SMM if found */ |
| 778 | if (gnvs_address && *gnvs_address) { |
| 779 | printk(BIOS_DEBUG, "Restore GNVS pointer to 0x%08x\n", |
| 780 | *gnvs_address); |
| 781 | smm_setup_structures((void *)*gnvs_address, NULL, NULL); |
Stefan Reinauer | cb91e15 | 2012-04-03 23:28:22 +0200 | [diff] [blame] | 782 | } |
Aaron Durbin | 0a6c20a | 2013-04-24 22:33:08 -0500 | [diff] [blame] | 783 | #endif |
| 784 | |
| 785 | /* Call mainboard resume handler first, if defined. */ |
| 786 | if (mainboard_suspend_resume) |
| 787 | mainboard_suspend_resume(); |
Aaron Durbin | 0a6c20a | 2013-04-24 22:33:08 -0500 | [diff] [blame] | 788 | |
| 789 | post_code(POST_OS_RESUME); |
| 790 | acpi_jump_to_wakeup(wake_vec); |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 793 | /* This is to be filled by SB code - startup value what was found. */ |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 794 | u8 acpi_slp_type = 0; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 795 | |
Kyösti Mälkki | db8693b | 2014-06-19 23:29:07 +0300 | [diff] [blame] | 796 | static void acpi_handoff_wakeup(void) |
| 797 | { |
| 798 | static int once = 0; |
| 799 | if (once) |
| 800 | return; |
| 801 | if (acpi_get_sleep_type) |
| 802 | acpi_slp_type = acpi_get_sleep_type(); |
| 803 | once = 1; |
| 804 | } |
| 805 | |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame] | 806 | int acpi_is_wakeup(void) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 807 | { |
Kyösti Mälkki | db8693b | 2014-06-19 23:29:07 +0300 | [diff] [blame] | 808 | acpi_handoff_wakeup(); |
Tobias Diedrich | 4e22a3b | 2010-12-13 22:39:46 +0100 | [diff] [blame] | 809 | /* Both resume from S2 and resume from S3 restart at CPU reset */ |
| 810 | return (acpi_slp_type == 3 || acpi_slp_type == 2); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Kyösti Mälkki | 4d9b772 | 2014-06-19 19:45:40 +0300 | [diff] [blame] | 813 | int acpi_is_wakeup_s3(void) |
| 814 | { |
Kyösti Mälkki | db8693b | 2014-06-19 23:29:07 +0300 | [diff] [blame] | 815 | acpi_handoff_wakeup(); |
Kyösti Mälkki | 4d9b772 | 2014-06-19 19:45:40 +0300 | [diff] [blame] | 816 | return (acpi_slp_type == 3); |
| 817 | } |
| 818 | |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame] | 819 | void acpi_fail_wakeup(void) |
| 820 | { |
| 821 | if (acpi_slp_type == 3 || acpi_slp_type == 2) |
| 822 | acpi_slp_type = 0; |
| 823 | } |
| 824 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 825 | static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp) |
| 826 | { |
| 827 | if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0) |
| 828 | return NULL; |
| 829 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 830 | printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 831 | |
| 832 | if (acpi_checksum((void *)rsdp, 20) != 0) |
| 833 | return NULL; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 834 | printk(BIOS_DEBUG, "Checksum 1 passed\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 835 | |
| 836 | if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp, |
| 837 | rsdp->length) != 0)) |
| 838 | return NULL; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 839 | printk(BIOS_DEBUG, "Checksum 2 passed all OK\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 840 | |
| 841 | return rsdp; |
| 842 | } |
| 843 | |
| 844 | static acpi_rsdp_t *rsdp; |
| 845 | |
| 846 | void *acpi_get_wakeup_rsdp(void) |
| 847 | { |
| 848 | return rsdp; |
| 849 | } |
| 850 | |
| 851 | void *acpi_find_wakeup_vector(void) |
| 852 | { |
| 853 | char *p, *end; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 854 | acpi_rsdt_t *rsdt; |
| 855 | acpi_facs_t *facs; |
Martin Roth | c5f4926 | 2012-12-14 19:17:55 -0700 | [diff] [blame] | 856 | acpi_fadt_t *fadt = NULL; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 857 | void *wake_vec; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 858 | int i; |
| 859 | |
| 860 | rsdp = NULL; |
| 861 | |
| 862 | if (!acpi_is_wakeup()) |
| 863 | return NULL; |
| 864 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 865 | printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 866 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 867 | /* Find RSDP. */ |
| 868 | for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) { |
| 869 | if ((rsdp = valid_rsdp((acpi_rsdp_t *)p))) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 870 | break; |
| 871 | } |
| 872 | |
| 873 | if (rsdp == NULL) |
| 874 | return NULL; |
| 875 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 876 | printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 877 | rsdt = (acpi_rsdt_t *) rsdp->rsdt_address; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 878 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 879 | end = (char *)rsdt + rsdt->header.length; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 880 | 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] | 881 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 882 | for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) { |
| 883 | fadt = (acpi_fadt_t *)rsdt->entry[i]; |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 884 | if (strncmp((char *)fadt, "FACP", 4) == 0) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 885 | break; |
| 886 | fadt = NULL; |
| 887 | } |
| 888 | |
| 889 | if (fadt == NULL) |
| 890 | return NULL; |
| 891 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 892 | printk(BIOS_DEBUG, "FADT found at %p\n", fadt); |
Stefan Reinauer | 69390db | 2009-05-26 12:33:52 +0000 | [diff] [blame] | 893 | facs = (acpi_facs_t *)fadt->firmware_ctrl; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 894 | |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 895 | if (facs == NULL) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 896 | printk(BIOS_DEBUG, "No FACS found, wake up from S3 not " |
| 897 | "possible.\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 898 | return NULL; |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 899 | } |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 900 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 901 | printk(BIOS_DEBUG, "FACS found at %p\n", facs); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 902 | wake_vec = (void *)facs->firmware_waking_vector; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 903 | printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 904 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 905 | return wake_vec; |
| 906 | } |
| 907 | |
Tobias Diedrich | 4e22a3b | 2010-12-13 22:39:46 +0100 | [diff] [blame] | 908 | #if CONFIG_SMP |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 909 | extern char *lowmem_backup; |
| 910 | extern char *lowmem_backup_ptr; |
| 911 | extern int lowmem_backup_size; |
Tobias Diedrich | 4e22a3b | 2010-12-13 22:39:46 +0100 | [diff] [blame] | 912 | #endif |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 913 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 914 | #define WAKEUP_BASE 0x600 |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 915 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 916 | void (*acpi_do_wakeup)(u32 vector, u32 backup_source, u32 backup_target, |
Stefan Reinauer | 399486e | 2012-12-06 13:54:29 -0800 | [diff] [blame] | 917 | u32 backup_size) asmlinkage = (void *)WAKEUP_BASE; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 918 | |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 919 | extern unsigned char __wakeup; |
| 920 | extern unsigned int __wakeup_size; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 921 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 922 | void acpi_jump_to_wakeup(void *vector) |
| 923 | { |
Aaron Durbin | 8e4a355 | 2013-02-08 17:28:04 -0600 | [diff] [blame] | 924 | u32 acpi_backup_memory = 0; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 925 | |
Kyösti Mälkki | 2ca2afe | 2014-06-17 15:41:37 +0300 | [diff] [blame] | 926 | if (HIGH_MEMORY_SAVE && acpi_s3_resume_allowed()) { |
| 927 | acpi_backup_memory = (u32)cbmem_find(CBMEM_ID_RESUME); |
| 928 | |
| 929 | if (!acpi_backup_memory) { |
| 930 | printk(BIOS_WARNING, "ACPI: Backup memory missing. " |
| 931 | "No S3 resume.\n"); |
| 932 | return; |
| 933 | } |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 934 | } |
| 935 | |
Tobias Diedrich | 4e22a3b | 2010-12-13 22:39:46 +0100 | [diff] [blame] | 936 | #if CONFIG_SMP |
Martin Roth | 7b5f8ef | 2013-07-08 16:22:10 -0600 | [diff] [blame] | 937 | // 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] | 938 | /* |
| 939 | * Just restore the SMP trampoline and continue with wakeup on |
| 940 | * assembly level. |
| 941 | */ |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 942 | memcpy(lowmem_backup_ptr, lowmem_backup, lowmem_backup_size); |
Tobias Diedrich | 4e22a3b | 2010-12-13 22:39:46 +0100 | [diff] [blame] | 943 | #endif |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 944 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 945 | /* Copy wakeup trampoline in place. */ |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 946 | memcpy((void *)WAKEUP_BASE, &__wakeup, __wakeup_size); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 947 | |
Duncan Laurie | cde7801 | 2011-10-19 15:32:39 -0700 | [diff] [blame] | 948 | #if CONFIG_COLLECT_TIMESTAMPS |
| 949 | timestamp_add_now(TS_ACPI_WAKE_JUMP); |
| 950 | #endif |
| 951 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 952 | acpi_do_wakeup((u32)vector, acpi_backup_memory, CONFIG_RAMBASE, |
| 953 | HIGH_MEMORY_SAVE); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 954 | } |
| 955 | #endif |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 956 | |
| 957 | void acpi_save_gnvs(u32 gnvs_address) |
| 958 | { |
Duncan Laurie | 9c07c8f | 2013-03-22 11:08:39 -0700 | [diff] [blame] | 959 | u32 *gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS_PTR, sizeof(*gnvs)); |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 960 | if (gnvs) |
| 961 | *gnvs = gnvs_address; |
| 962 | } |