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