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