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 |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 9 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, |
| 10 | * Raptor Engineering |
Mario Scheithauer | f1eb0ea | 2017-11-21 13:52:53 +0100 | [diff] [blame] | 11 | * Copyright (C) 2016-2017 Siemens AG |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 12 | * |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 13 | * ACPI FADT, FACS, and DSDT table support added by |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 14 | * Nick Barker <nick.barker9@btinternet.com>, and those portions |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 15 | * Copyright (C) 2004 Nick Barker |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 16 | * |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 17 | * Copyright (C) 2005 ADVANCED MICRO DEVICES, INC. All Rights Reserved. |
Stefan Reinauer | d6edf7a | 2006-01-05 00:19:52 +0000 | [diff] [blame] | 18 | * 2005.9 yhlu add SRAT table generation |
Martin Roth | 9df9e939 | 2016-01-12 15:55:28 -0700 | [diff] [blame] | 19 | * |
| 20 | * This program is free software; you can redistribute it and/or modify |
| 21 | * it under the terms of the GNU General Public License as published by |
| 22 | * the Free Software Foundation; version 2 of the License. |
| 23 | * |
| 24 | * This program is distributed in the hope that it will be useful, |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | * GNU General Public License for more details. |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 28 | */ |
| 29 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 30 | /* |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 31 | * Each system port implementing ACPI has to provide two functions: |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 32 | * |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 33 | * write_acpi_tables() |
| 34 | * acpi_dump_apics() |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 35 | * |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 36 | * See Kontron 986LCD-M port for a good example of an ACPI implementation |
| 37 | * in coreboot. |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 38 | */ |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 39 | |
| 40 | #include <console/console.h> |
| 41 | #include <string.h> |
| 42 | #include <arch/acpi.h> |
Martin Roth | a66df49 | 2016-09-06 10:22:34 -0600 | [diff] [blame] | 43 | #include <arch/acpi_ivrs.h> |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 44 | #include <arch/acpigen.h> |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 45 | #include <device/pci.h> |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 46 | #include <cbmem.h> |
Patrick Georgi | c8feedd | 2012-02-16 18:43:25 +0100 | [diff] [blame] | 47 | #include <cpu/x86/lapic_def.h> |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 48 | #include <cpu/cpu.h> |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 49 | #include <cbfs.h> |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 50 | |
| 51 | u8 acpi_checksum(u8 *table, u32 length) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 52 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 53 | u8 ret = 0; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 54 | while (length--) { |
| 55 | ret += *table; |
| 56 | table++; |
| 57 | } |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 58 | return -ret; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 61 | /** |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 62 | * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length |
| 63 | * and checksum. |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 64 | */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 65 | void acpi_add_table(acpi_rsdp_t *rsdp, void *table) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 66 | { |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 67 | int i, entries_num; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 68 | acpi_rsdt_t *rsdt; |
| 69 | acpi_xsdt_t *xsdt = NULL; |
| 70 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 71 | /* The RSDT is mandatory... */ |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 72 | rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 73 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 74 | /* ...while the XSDT is not. */ |
| 75 | if (rsdp->xsdt_address) |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 76 | xsdt = (acpi_xsdt_t *)((uintptr_t)rsdp->xsdt_address); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 77 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 78 | /* This should always be MAX_ACPI_TABLES. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 79 | entries_num = ARRAY_SIZE(rsdt->entry); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 80 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 81 | for (i = 0; i < entries_num; i++) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 82 | if (rsdt->entry[i] == 0) |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 83 | break; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 86 | if (i >= entries_num) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 87 | 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] | 88 | "too many tables.\n"); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 89 | return; |
| 90 | } |
| 91 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 92 | /* Add table to the RSDT. */ |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 93 | rsdt->entry[i] = (uintptr_t)table; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 94 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 95 | /* Fix RSDT length or the kernel will assume invalid entries. */ |
| 96 | rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i + 1)); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 97 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 98 | /* Re-calculate checksum. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 99 | rsdt->header.checksum = 0; /* Hope this won't get optimized away */ |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 100 | rsdt->header.checksum = acpi_checksum((u8 *)rsdt, rsdt->header.length); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 101 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 102 | /* |
| 103 | * 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] | 104 | * now we want the XSDT and RSDT to always be in sync in coreboot. |
| 105 | */ |
| 106 | if (xsdt) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 107 | /* Add table to the XSDT. */ |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 108 | xsdt->entry[i] = (u64)(uintptr_t)table; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 109 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 110 | /* Fix XSDT length. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 111 | xsdt->header.length = sizeof(acpi_header_t) + |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 112 | (sizeof(u64) * (i + 1)); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 113 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 114 | /* Re-calculate checksum. */ |
| 115 | xsdt->header.checksum = 0; |
| 116 | xsdt->header.checksum = acpi_checksum((u8 *)xsdt, |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 117 | xsdt->header.length); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 120 | 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] | 121 | i + 1, entries_num, rsdt->header.length); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 124 | 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] | 125 | u16 seg_nr, u8 start, u8 end) |
Stefan Reinauer | 26d431a | 2009-01-20 19:17:51 +0000 | [diff] [blame] | 126 | { |
Vladimir Serbinenko | 60fccdc | 2014-10-05 11:05:16 +0200 | [diff] [blame] | 127 | memset(mmconfig, 0, sizeof(*mmconfig)); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 128 | mmconfig->base_address = base; |
| 129 | mmconfig->base_reserved = 0; |
| 130 | mmconfig->pci_segment_group_number = seg_nr; |
| 131 | mmconfig->start_bus_number = start; |
| 132 | mmconfig->end_bus_number = end; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 133 | |
| 134 | return sizeof(acpi_mcfg_mmconfig_t); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 137 | 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] | 138 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 139 | lapic->type = 0; /* Local APIC structure */ |
| 140 | lapic->length = sizeof(acpi_madt_lapic_t); |
| 141 | lapic->flags = (1 << 0); /* Processor/LAPIC enabled */ |
| 142 | lapic->processor_id = cpu; |
| 143 | lapic->apic_id = apic; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 144 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 145 | return lapic->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 148 | unsigned long acpi_create_madt_lapics(unsigned long current) |
| 149 | { |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 150 | struct device *cpu; |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 151 | int index = 0; |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 152 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 153 | for (cpu = all_devices; cpu; cpu = cpu->next) { |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 154 | if ((cpu->path.type != DEVICE_PATH_APIC) || |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 155 | (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) { |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 156 | continue; |
| 157 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 158 | if (!cpu->enabled) |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 159 | continue; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 160 | current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 161 | index, cpu->path.apic.apic_id); |
| 162 | index++; |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 163 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 164 | |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 165 | return current; |
| 166 | } |
| 167 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 168 | 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] | 169 | u32 gsi_base) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 170 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 171 | ioapic->type = 1; /* I/O APIC structure */ |
| 172 | ioapic->length = sizeof(acpi_madt_ioapic_t); |
| 173 | ioapic->reserved = 0x00; |
| 174 | ioapic->gsi_base = gsi_base; |
| 175 | ioapic->ioapic_id = id; |
| 176 | ioapic->ioapic_addr = addr; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 177 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 178 | return ioapic->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 181 | int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride, |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 182 | u8 bus, u8 source, u32 gsirq, u16 flags) |
| 183 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 184 | irqoverride->type = 2; /* Interrupt source override */ |
| 185 | irqoverride->length = sizeof(acpi_madt_irqoverride_t); |
| 186 | irqoverride->bus = bus; |
| 187 | irqoverride->source = source; |
| 188 | irqoverride->gsirq = gsirq; |
| 189 | irqoverride->flags = flags; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 190 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 191 | return irqoverride->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 194 | 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] | 195 | u16 flags, u8 lint) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 196 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 197 | lapic_nmi->type = 4; /* Local APIC NMI structure */ |
| 198 | lapic_nmi->length = sizeof(acpi_madt_lapic_nmi_t); |
| 199 | lapic_nmi->flags = flags; |
| 200 | lapic_nmi->processor_id = cpu; |
| 201 | lapic_nmi->lint = lint; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 202 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 203 | return lapic_nmi->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 206 | void acpi_create_madt(acpi_madt_t *madt) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 207 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 208 | acpi_header_t *header = &(madt->header); |
| 209 | unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 210 | |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 211 | memset((void *)madt, 0, sizeof(acpi_madt_t)); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 212 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 213 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 214 | memcpy(header->signature, "APIC", 4); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 215 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 216 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 217 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 218 | |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 219 | header->length = sizeof(acpi_madt_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 220 | header->revision = get_acpi_table_revision(MADT); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 221 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 222 | madt->lapic_addr = LOCAL_APIC_ADDR; |
| 223 | madt->flags = 0x1; /* PCAT_COMPAT */ |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 224 | |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 225 | current = acpi_fill_madt(current); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 226 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 227 | /* (Re)calculate length and checksum. */ |
| 228 | header->length = current - (unsigned long)madt; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 229 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 230 | header->checksum = acpi_checksum((void *)madt, header->length); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 233 | /* MCFG is defined in the PCI Firmware Specification 3.0. */ |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 234 | void acpi_create_mcfg(acpi_mcfg_t *mcfg) |
| 235 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 236 | acpi_header_t *header = &(mcfg->header); |
| 237 | unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 238 | |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 239 | memset((void *)mcfg, 0, sizeof(acpi_mcfg_t)); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 240 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 241 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 242 | memcpy(header->signature, "MCFG", 4); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 243 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 244 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 245 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 246 | |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 247 | header->length = sizeof(acpi_mcfg_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 248 | header->revision = get_acpi_table_revision(MCFG); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 249 | |
| 250 | current = acpi_fill_mcfg(current); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 251 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 252 | /* (Re)calculate length and checksum. */ |
| 253 | header->length = current - (unsigned long)mcfg; |
| 254 | header->checksum = acpi_checksum((void *)mcfg, header->length); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 257 | static void *get_tcpa_log(u32 *size) |
| 258 | { |
| 259 | const struct cbmem_entry *ce; |
| 260 | const u32 tcpa_default_log_len = 0x10000; |
| 261 | void *lasa; |
Philipp Deppenwiese | 791ba97 | 2018-07-30 01:15:20 +0200 | [diff] [blame] | 262 | ce = cbmem_entry_find(CBMEM_ID_TCPA_TCG_LOG); |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 263 | if (ce) { |
| 264 | lasa = cbmem_entry_start(ce); |
| 265 | *size = cbmem_entry_size(ce); |
| 266 | printk(BIOS_DEBUG, "TCPA log found at %p\n", lasa); |
| 267 | return lasa; |
| 268 | } |
Philipp Deppenwiese | 791ba97 | 2018-07-30 01:15:20 +0200 | [diff] [blame] | 269 | lasa = cbmem_add(CBMEM_ID_TCPA_TCG_LOG, tcpa_default_log_len); |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 270 | if (!lasa) { |
| 271 | printk(BIOS_ERR, "TCPA log creation failed\n"); |
| 272 | return NULL; |
| 273 | } |
| 274 | |
| 275 | printk(BIOS_DEBUG, "TCPA log created at %p\n", lasa); |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 276 | memset(lasa, 0, tcpa_default_log_len); |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 277 | |
| 278 | *size = tcpa_default_log_len; |
| 279 | return lasa; |
| 280 | } |
| 281 | |
| 282 | static void acpi_create_tcpa(acpi_tcpa_t *tcpa) |
| 283 | { |
| 284 | acpi_header_t *header = &(tcpa->header); |
| 285 | u32 tcpa_log_len; |
| 286 | void *lasa; |
| 287 | |
| 288 | memset((void *)tcpa, 0, sizeof(acpi_tcpa_t)); |
| 289 | |
| 290 | lasa = get_tcpa_log(&tcpa_log_len); |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 291 | if (!lasa) |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 292 | return; |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 293 | |
| 294 | /* Fill out header fields. */ |
| 295 | memcpy(header->signature, "TCPA", 4); |
| 296 | memcpy(header->oem_id, OEM_ID, 6); |
| 297 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 298 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 299 | |
| 300 | header->length = sizeof(acpi_tcpa_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 301 | header->revision = get_acpi_table_revision(TCPA); |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 302 | |
| 303 | tcpa->platform_class = 0; |
| 304 | tcpa->laml = tcpa_log_len; |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 305 | tcpa->lasa = (uintptr_t) lasa; |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 306 | |
| 307 | /* Calculate checksum. */ |
| 308 | header->checksum = acpi_checksum((void *)tcpa, header->length); |
| 309 | } |
| 310 | |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 311 | static void acpi_create_tpm2(acpi_tpm2_t *tpm2) |
| 312 | { |
| 313 | acpi_header_t *header = &(tpm2->header); |
| 314 | |
| 315 | memset((void *)tpm2, 0, sizeof(acpi_tpm2_t)); |
| 316 | |
| 317 | /* Fill out header fields. */ |
| 318 | memcpy(header->signature, "TPM2", 4); |
| 319 | memcpy(header->oem_id, OEM_ID, 6); |
| 320 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 321 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 322 | |
| 323 | header->length = sizeof(acpi_tpm2_t); |
| 324 | header->revision = get_acpi_table_revision(TPM2); |
| 325 | |
| 326 | /* Hard to detect for coreboot. Just set it to 0 */ |
| 327 | tpm2->platform_class = 0; |
| 328 | /* Must be set to 0 for TIS interface support */ |
| 329 | tpm2->control_area = 0; |
| 330 | /* coreboot only supports the TIS interface driver. */ |
| 331 | tpm2->start_method = 6; |
| 332 | memset(tpm2->msp, 0, sizeof(tpm2->msp)); |
| 333 | |
| 334 | /* Calculate checksum. */ |
| 335 | header->checksum = acpi_checksum((void *)tpm2, header->length); |
| 336 | } |
| 337 | |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 338 | static void acpi_ssdt_write_cbtable(void) |
| 339 | { |
| 340 | const struct cbmem_entry *cbtable; |
| 341 | uintptr_t base; |
| 342 | uint32_t size; |
| 343 | |
| 344 | cbtable = cbmem_entry_find(CBMEM_ID_CBTABLE); |
| 345 | if (!cbtable) |
| 346 | return; |
| 347 | base = (uintptr_t)cbmem_entry_start(cbtable); |
| 348 | size = cbmem_entry_size(cbtable); |
| 349 | |
| 350 | acpigen_write_device("CTBL"); |
| 351 | acpigen_write_coreboot_hid(COREBOOT_ACPI_ID_CBTABLE); |
| 352 | acpigen_write_name_integer("_UID", 0); |
David Wu | 5dff396 | 2018-03-21 16:48:53 +0800 | [diff] [blame] | 353 | acpigen_write_STA(ACPI_STATUS_DEVICE_HIDDEN_ON); |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 354 | acpigen_write_name("_CRS"); |
| 355 | acpigen_write_resourcetemplate_header(); |
| 356 | acpigen_write_mem32fixed(0, base, size); |
| 357 | acpigen_write_resourcetemplate_footer(); |
| 358 | acpigen_pop_len(); |
| 359 | } |
| 360 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 361 | 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] | 362 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 363 | unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t); |
| 364 | |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 365 | memset((void *)ssdt, 0, sizeof(acpi_header_t)); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 366 | |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 367 | memcpy(&ssdt->signature, "SSDT", 4); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 368 | ssdt->revision = get_acpi_table_revision(SSDT); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 369 | memcpy(&ssdt->oem_id, OEM_ID, 6); |
| 370 | memcpy(&ssdt->oem_table_id, oem_table_id, 8); |
| 371 | ssdt->oem_revision = 42; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 372 | memcpy(&ssdt->asl_compiler_id, ASLC, 4); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 373 | ssdt->asl_compiler_revision = 42; |
| 374 | ssdt->length = sizeof(acpi_header_t); |
| 375 | |
Stefan Reinauer | 8dcd50b | 2009-03-06 17:24:29 +0000 | [diff] [blame] | 376 | acpigen_set_current((char *) current); |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 377 | |
| 378 | /* Write object to declare coreboot tables */ |
| 379 | acpi_ssdt_write_cbtable(); |
| 380 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 381 | { |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 382 | struct device *dev; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 383 | for (dev = all_devices; dev; dev = dev->next) |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 384 | if (dev->ops && dev->ops->acpi_fill_ssdt_generator) |
Alexander Couzens | 5eea458 | 2015-04-12 22:18:55 +0200 | [diff] [blame] | 385 | dev->ops->acpi_fill_ssdt_generator(dev); |
Vladimir Serbinenko | 0a66991 | 2014-10-05 14:34:17 +0200 | [diff] [blame] | 386 | current = (unsigned long) acpigen_get_current(); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 387 | } |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 388 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 389 | /* (Re)calculate length and checksum. */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 390 | ssdt->length = current - (unsigned long)ssdt; |
| 391 | ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length); |
| 392 | } |
| 393 | |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 394 | int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic) |
| 395 | { |
Myles Watson | 0b4c9f0 | 2009-03-10 18:06:47 +0000 | [diff] [blame] | 396 | memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t)); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 397 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 398 | lapic->type = 0; /* Processor local APIC/SAPIC affinity structure */ |
| 399 | lapic->length = sizeof(acpi_srat_lapic_t); |
| 400 | lapic->flags = (1 << 0); /* Enabled (the use of this structure). */ |
| 401 | lapic->proximity_domain_7_0 = node; |
| 402 | /* TODO: proximity_domain_31_8, local SAPIC EID, clock domain. */ |
| 403 | lapic->apic_id = apic; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 404 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 405 | return lapic->length; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 408 | 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] | 409 | u32 flags) |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 410 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 411 | mem->type = 1; /* Memory affinity structure */ |
| 412 | mem->length = sizeof(acpi_srat_mem_t); |
| 413 | mem->base_address_low = (basek << 10); |
| 414 | mem->base_address_high = (basek >> (32 - 10)); |
| 415 | mem->length_low = (sizek << 10); |
| 416 | mem->length_high = (sizek >> (32 - 10)); |
| 417 | mem->proximity_domain = node; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 418 | mem->flags = flags; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 419 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 420 | return mem->length; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 423 | /* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */ |
Vladimir Serbinenko | 5e59757 | 2014-10-11 23:45:40 +0200 | [diff] [blame] | 424 | void acpi_create_srat(acpi_srat_t *srat, |
| 425 | unsigned long (*acpi_fill_srat)(unsigned long current)) |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 426 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 427 | acpi_header_t *header = &(srat->header); |
| 428 | unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 429 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 430 | memset((void *)srat, 0, sizeof(acpi_srat_t)); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 431 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 432 | /* Fill out header fields. */ |
| 433 | memcpy(header->signature, "SRAT", 4); |
| 434 | memcpy(header->oem_id, OEM_ID, 6); |
| 435 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 436 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 437 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 438 | header->length = sizeof(acpi_srat_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 439 | header->revision = get_acpi_table_revision(SRAT); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 440 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 441 | srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */ |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 442 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 443 | current = acpi_fill_srat(current); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 444 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 445 | /* (Re)calculate length and checksum. */ |
| 446 | header->length = current - (unsigned long)srat; |
| 447 | header->checksum = acpi_checksum((void *)srat, header->length); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Nico Huber | e561f35 | 2015-10-26 11:51:25 +0100 | [diff] [blame] | 450 | void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags, |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 451 | unsigned long (*acpi_fill_dmar)(unsigned long)) |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 452 | { |
| 453 | acpi_header_t *header = &(dmar->header); |
| 454 | unsigned long current = (unsigned long)dmar + sizeof(acpi_dmar_t); |
| 455 | |
| 456 | memset((void *)dmar, 0, sizeof(acpi_dmar_t)); |
| 457 | |
| 458 | /* Fill out header fields. */ |
| 459 | memcpy(header->signature, "DMAR", 4); |
| 460 | memcpy(header->oem_id, OEM_ID, 6); |
| 461 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 462 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 463 | |
| 464 | header->length = sizeof(acpi_dmar_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 465 | header->revision = get_acpi_table_revision(DMAR); |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 466 | |
Jacob Laska | f3f654d | 2016-03-15 21:53:27 -0500 | [diff] [blame] | 467 | dmar->host_address_width = cpu_phys_address_size() - 1; |
Nico Huber | e561f35 | 2015-10-26 11:51:25 +0100 | [diff] [blame] | 468 | dmar->flags = flags; |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 469 | |
| 470 | current = acpi_fill_dmar(current); |
| 471 | |
| 472 | /* (Re)calculate length and checksum. */ |
| 473 | header->length = current - (unsigned long)dmar; |
| 474 | header->checksum = acpi_checksum((void *)dmar, header->length); |
| 475 | } |
| 476 | |
| 477 | unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags, |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 478 | u16 segment, u64 bar) |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 479 | { |
| 480 | dmar_entry_t *drhd = (dmar_entry_t *)current; |
| 481 | memset(drhd, 0, sizeof(*drhd)); |
| 482 | drhd->type = DMAR_DRHD; |
| 483 | drhd->length = sizeof(*drhd); /* will be fixed up later */ |
| 484 | drhd->flags = flags; |
| 485 | drhd->segment = segment; |
| 486 | drhd->bar = bar; |
| 487 | |
| 488 | return drhd->length; |
| 489 | } |
| 490 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 491 | unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment, |
| 492 | u64 bar, u64 limit) |
| 493 | { |
| 494 | dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)current; |
| 495 | memset(rmrr, 0, sizeof(*rmrr)); |
| 496 | rmrr->type = DMAR_RMRR; |
| 497 | rmrr->length = sizeof(*rmrr); /* will be fixed up later */ |
| 498 | rmrr->segment = segment; |
| 499 | rmrr->bar = bar; |
| 500 | rmrr->limit = limit; |
| 501 | |
| 502 | return rmrr->length; |
| 503 | } |
| 504 | |
Werner Zeh | d4d7695 | 2016-07-27 06:56:36 +0200 | [diff] [blame] | 505 | unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags, |
| 506 | u16 segment) |
| 507 | { |
| 508 | dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)current; |
| 509 | memset(atsr, 0, sizeof(*atsr)); |
| 510 | atsr->type = DMAR_ATSR; |
| 511 | atsr->length = sizeof(*atsr); /* will be fixed up later */ |
| 512 | atsr->flags = flags; |
| 513 | atsr->segment = segment; |
| 514 | |
| 515 | return atsr->length; |
| 516 | } |
| 517 | |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 518 | void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current) |
| 519 | { |
| 520 | dmar_entry_t *drhd = (dmar_entry_t *)base; |
| 521 | drhd->length = current - base; |
| 522 | } |
| 523 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 524 | void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current) |
| 525 | { |
| 526 | dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)base; |
| 527 | rmrr->length = current - base; |
| 528 | } |
| 529 | |
Werner Zeh | d4d7695 | 2016-07-27 06:56:36 +0200 | [diff] [blame] | 530 | void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current) |
| 531 | { |
| 532 | dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)base; |
| 533 | atsr->length = current - base; |
| 534 | } |
| 535 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 536 | static unsigned long acpi_create_dmar_ds(unsigned long current, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 537 | enum dev_scope_type type, u8 enumeration_id, u8 bus, u8 dev, u8 fn) |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 538 | { |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 539 | /* we don't support longer paths yet */ |
| 540 | const size_t dev_scope_length = sizeof(dev_scope_t) + 2; |
| 541 | |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 542 | dev_scope_t *ds = (dev_scope_t *)current; |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 543 | memset(ds, 0, dev_scope_length); |
| 544 | ds->type = type; |
| 545 | ds->length = dev_scope_length; |
| 546 | ds->enumeration = enumeration_id; |
| 547 | ds->start_bus = bus; |
| 548 | ds->path[0].dev = dev; |
| 549 | ds->path[0].fn = fn; |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 550 | |
| 551 | return ds->length; |
| 552 | } |
| 553 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 554 | unsigned long acpi_create_dmar_ds_pci_br(unsigned long current, u8 bus, |
Werner Zeh | 21a5bff | 2016-07-27 07:07:20 +0200 | [diff] [blame] | 555 | u8 dev, u8 fn) |
| 556 | { |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 557 | return acpi_create_dmar_ds(current, |
Werner Zeh | 21a5bff | 2016-07-27 07:07:20 +0200 | [diff] [blame] | 558 | SCOPE_PCI_SUB, 0, bus, dev, fn); |
| 559 | } |
| 560 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 561 | unsigned long acpi_create_dmar_ds_pci(unsigned long current, u8 bus, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 562 | u8 dev, u8 fn) |
| 563 | { |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 564 | return acpi_create_dmar_ds(current, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 565 | SCOPE_PCI_ENDPOINT, 0, bus, dev, fn); |
| 566 | } |
| 567 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 568 | unsigned long acpi_create_dmar_ds_ioapic(unsigned long current, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 569 | u8 enumeration_id, u8 bus, u8 dev, u8 fn) |
| 570 | { |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 571 | return acpi_create_dmar_ds(current, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 572 | SCOPE_IOAPIC, enumeration_id, bus, dev, fn); |
| 573 | } |
| 574 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 575 | unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 576 | u8 enumeration_id, u8 bus, u8 dev, u8 fn) |
| 577 | { |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 578 | return acpi_create_dmar_ds(current, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 579 | SCOPE_MSI_HPET, enumeration_id, bus, dev, fn); |
| 580 | } |
| 581 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 582 | /* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */ |
Vladimir Serbinenko | 5e59757 | 2014-10-11 23:45:40 +0200 | [diff] [blame] | 583 | void acpi_create_slit(acpi_slit_t *slit, |
| 584 | unsigned long (*acpi_fill_slit)(unsigned long current)) |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 585 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 586 | acpi_header_t *header = &(slit->header); |
| 587 | unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 588 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 589 | memset((void *)slit, 0, sizeof(acpi_slit_t)); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 590 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 591 | /* Fill out header fields. */ |
| 592 | memcpy(header->signature, "SLIT", 4); |
| 593 | memcpy(header->oem_id, OEM_ID, 6); |
| 594 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 595 | memcpy(header->asl_compiler_id, ASLC, 4); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 596 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 597 | header->length = sizeof(acpi_slit_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 598 | header->revision = get_acpi_table_revision(SLIT); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 599 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 600 | current = acpi_fill_slit(current); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 601 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 602 | /* (Re)calculate length and checksum. */ |
| 603 | header->length = current - (unsigned long)slit; |
| 604 | header->checksum = acpi_checksum((void *)slit, header->length); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 607 | /* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */ |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 608 | void acpi_create_hpet(acpi_hpet_t *hpet) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 609 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 610 | acpi_header_t *header = &(hpet->header); |
| 611 | acpi_addr_t *addr = &(hpet->addr); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 612 | |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 613 | memset((void *)hpet, 0, sizeof(acpi_hpet_t)); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 614 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 615 | /* Fill out header fields. */ |
Stefan Reinauer | 4704dc5 | 2009-07-22 01:11:37 +0000 | [diff] [blame] | 616 | memcpy(header->signature, "HPET", 4); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 617 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 618 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 619 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 620 | |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 621 | header->length = sizeof(acpi_hpet_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 622 | header->revision = get_acpi_table_revision(HPET); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 623 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 624 | /* Fill out HPET address. */ |
| 625 | addr->space_id = 0; /* Memory */ |
| 626 | addr->bit_width = 64; |
| 627 | addr->bit_offset = 0; |
Patrick Georgi | 9aeb694 | 2012-10-05 21:54:38 +0200 | [diff] [blame] | 628 | addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff; |
| 629 | addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 630 | |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 631 | hpet->id = *(unsigned int *)CONFIG_HPET_ADDRESS; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 632 | hpet->number = 0; |
Patrick Georgi | 9aeb694 | 2012-10-05 21:54:38 +0200 | [diff] [blame] | 633 | hpet->min_tick = CONFIG_HPET_MIN_TICKS; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 634 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 635 | header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 636 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 637 | |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 638 | void acpi_create_vfct(struct device *device, |
| 639 | struct acpi_vfct *vfct, |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 640 | unsigned long (*acpi_fill_vfct)(struct device *device, |
| 641 | struct acpi_vfct *vfct_struct, unsigned long current)) |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 642 | { |
| 643 | acpi_header_t *header = &(vfct->header); |
| 644 | unsigned long current = (unsigned long)vfct + sizeof(struct acpi_vfct); |
| 645 | |
| 646 | memset((void *)vfct, 0, sizeof(struct acpi_vfct)); |
| 647 | |
| 648 | /* Fill out header fields. */ |
| 649 | memcpy(header->signature, "VFCT", 4); |
| 650 | memcpy(header->oem_id, OEM_ID, 6); |
| 651 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 652 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 653 | |
| 654 | header->length = sizeof(struct acpi_vfct); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 655 | header->revision = get_acpi_table_revision(VFCT); |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 656 | |
| 657 | current = acpi_fill_vfct(device, vfct, current); |
| 658 | |
| 659 | /* (Re)calculate length and checksum. */ |
| 660 | header->length = current - (unsigned long)vfct; |
| 661 | header->checksum = acpi_checksum((void *)vfct, header->length); |
| 662 | } |
| 663 | |
Timothy Pearson | ff8ccf0 | 2015-08-11 17:48:32 -0500 | [diff] [blame] | 664 | void acpi_create_ivrs(acpi_ivrs_t *ivrs, |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 665 | unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct, |
| 666 | unsigned long current)) |
Timothy Pearson | ff8ccf0 | 2015-08-11 17:48:32 -0500 | [diff] [blame] | 667 | { |
| 668 | acpi_header_t *header = &(ivrs->header); |
| 669 | unsigned long current = (unsigned long)ivrs + sizeof(acpi_ivrs_t); |
| 670 | |
| 671 | memset((void *)ivrs, 0, sizeof(acpi_ivrs_t)); |
| 672 | |
| 673 | /* Fill out header fields. */ |
| 674 | memcpy(header->signature, "IVRS", 4); |
| 675 | memcpy(header->oem_id, OEM_ID, 6); |
| 676 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 677 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 678 | |
| 679 | header->length = sizeof(acpi_ivrs_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 680 | header->revision = get_acpi_table_revision(IVRS); |
Timothy Pearson | ff8ccf0 | 2015-08-11 17:48:32 -0500 | [diff] [blame] | 681 | |
| 682 | current = acpi_fill_ivrs(ivrs, current); |
| 683 | |
| 684 | /* (Re)calculate length and checksum. */ |
| 685 | header->length = current - (unsigned long)ivrs; |
| 686 | header->checksum = acpi_checksum((void *)ivrs, header->length); |
| 687 | } |
| 688 | |
Elyes HAOUAS | 9dd89cd | 2018-05-04 17:56:47 +0200 | [diff] [blame] | 689 | unsigned long acpi_write_hpet(struct device *device, unsigned long current, |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 690 | acpi_rsdp_t *rsdp) |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 691 | { |
| 692 | acpi_hpet_t *hpet; |
| 693 | |
| 694 | /* |
| 695 | * We explicitly add these tables later on: |
| 696 | */ |
| 697 | printk(BIOS_DEBUG, "ACPI: * HPET\n"); |
| 698 | |
| 699 | hpet = (acpi_hpet_t *) current; |
| 700 | current += sizeof(acpi_hpet_t); |
| 701 | current = ALIGN(current, 16); |
| 702 | acpi_create_hpet(hpet); |
| 703 | acpi_add_table(rsdp, hpet); |
| 704 | |
| 705 | return current; |
| 706 | } |
| 707 | |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 708 | void acpi_create_dbg2(acpi_dbg2_header_t *dbg2, |
| 709 | int port_type, int port_subtype, |
| 710 | acpi_addr_t *address, uint32_t address_size, |
| 711 | const char *device_path) |
| 712 | { |
| 713 | uintptr_t current; |
| 714 | acpi_dbg2_device_t *device; |
| 715 | uint32_t *dbg2_addr_size; |
| 716 | acpi_header_t *header; |
| 717 | size_t path_len; |
| 718 | const char *path; |
| 719 | char *namespace; |
| 720 | |
| 721 | /* Fill out header fields. */ |
| 722 | current = (uintptr_t)dbg2; |
| 723 | memset(dbg2, 0, sizeof(acpi_dbg2_header_t)); |
| 724 | header = &(dbg2->header); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 725 | header->revision = get_acpi_table_revision(DBG2); |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 726 | memcpy(header->signature, "DBG2", 4); |
| 727 | memcpy(header->oem_id, OEM_ID, 6); |
| 728 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 729 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 730 | |
| 731 | /* One debug device defined */ |
| 732 | dbg2->devices_offset = sizeof(acpi_dbg2_header_t); |
| 733 | dbg2->devices_count = 1; |
| 734 | current += sizeof(acpi_dbg2_header_t); |
| 735 | |
| 736 | /* Device comes after the header */ |
| 737 | device = (acpi_dbg2_device_t *)current; |
| 738 | memset(device, 0, sizeof(acpi_dbg2_device_t)); |
| 739 | current += sizeof(acpi_dbg2_device_t); |
| 740 | |
| 741 | device->revision = 0; |
| 742 | device->address_count = 1; |
| 743 | device->port_type = port_type; |
| 744 | device->port_subtype = port_subtype; |
| 745 | |
| 746 | /* Base Address comes after device structure */ |
| 747 | memcpy((void *)current, address, sizeof(acpi_addr_t)); |
| 748 | device->base_address_offset = current - (uintptr_t)device; |
| 749 | current += sizeof(acpi_addr_t); |
| 750 | |
| 751 | /* Address Size comes after address structure */ |
| 752 | dbg2_addr_size = (uint32_t *)current; |
| 753 | device->address_size_offset = current - (uintptr_t)device; |
| 754 | *dbg2_addr_size = address_size; |
| 755 | current += sizeof(uint32_t); |
| 756 | |
| 757 | /* Namespace string comes last, use '.' if not provided */ |
| 758 | path = device_path ? : "."; |
| 759 | /* Namespace string length includes NULL terminator */ |
| 760 | path_len = strlen(path) + 1; |
| 761 | namespace = (char *)current; |
| 762 | device->namespace_string_length = path_len; |
| 763 | device->namespace_string_offset = current - (uintptr_t)device; |
| 764 | strncpy(namespace, path, path_len); |
| 765 | current += path_len; |
| 766 | |
| 767 | /* Update structure lengths and checksum */ |
| 768 | device->length = current - (uintptr_t)device; |
| 769 | header->length = current - (uintptr_t)dbg2; |
| 770 | header->checksum = acpi_checksum((uint8_t *)dbg2, header->length); |
| 771 | } |
| 772 | |
| 773 | unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current, |
| 774 | struct device *dev, uint8_t access_size) |
| 775 | { |
| 776 | acpi_dbg2_header_t *dbg2 = (acpi_dbg2_header_t *)current; |
| 777 | struct resource *res; |
| 778 | acpi_addr_t address; |
| 779 | |
| 780 | if (!dev) { |
| 781 | printk(BIOS_ERR, "%s: Device not found\n", __func__); |
| 782 | return current; |
| 783 | } |
Mario Scheithauer | f1eb0ea | 2017-11-21 13:52:53 +0100 | [diff] [blame] | 784 | if (!dev->enabled) { |
| 785 | printk(BIOS_INFO, "%s: Device not enabled\n", __func__); |
| 786 | return current; |
| 787 | } |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 788 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 789 | if (!res) { |
| 790 | printk(BIOS_ERR, "%s: Unable to find resource for %s\n", |
| 791 | __func__, dev_path(dev)); |
| 792 | return current; |
| 793 | } |
| 794 | |
| 795 | memset(&address, 0, sizeof(address)); |
| 796 | if (res->flags & IORESOURCE_IO) |
| 797 | address.space_id = ACPI_ADDRESS_SPACE_IO; |
| 798 | else if (res->flags & IORESOURCE_MEM) |
| 799 | address.space_id = ACPI_ADDRESS_SPACE_MEMORY; |
| 800 | else { |
| 801 | printk(BIOS_ERR, "%s: Unknown address space type\n", __func__); |
| 802 | return current; |
| 803 | } |
| 804 | |
| 805 | address.addrl = (uint32_t)res->base; |
| 806 | address.addrh = (uint32_t)((res->base >> 32) & 0xffffffff); |
| 807 | address.access_size = access_size; |
| 808 | |
| 809 | acpi_create_dbg2(dbg2, |
| 810 | ACPI_DBG2_PORT_SERIAL, |
| 811 | ACPI_DBG2_PORT_SERIAL_16550, |
| 812 | &address, res->size, |
| 813 | acpi_device_path(dev)); |
| 814 | |
| 815 | if (dbg2->header.length) { |
| 816 | current += dbg2->header.length; |
| 817 | current = acpi_align_current(current); |
| 818 | acpi_add_table(rsdp, dbg2); |
| 819 | } |
| 820 | |
| 821 | return current; |
| 822 | } |
| 823 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 824 | void acpi_create_facs(acpi_facs_t *facs) |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 825 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 826 | memset((void *)facs, 0, sizeof(acpi_facs_t)); |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 827 | |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 828 | memcpy(facs->signature, "FACS", 4); |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 829 | facs->length = sizeof(acpi_facs_t); |
| 830 | facs->hardware_signature = 0; |
| 831 | facs->firmware_waking_vector = 0; |
| 832 | facs->global_lock = 0; |
| 833 | facs->flags = 0; |
| 834 | facs->x_firmware_waking_vector_l = 0; |
| 835 | facs->x_firmware_waking_vector_h = 0; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 836 | facs->version = get_acpi_table_revision(FACS); |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 837 | } |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 838 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 839 | static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id) |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 840 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 841 | acpi_header_t *header = &(rsdt->header); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 842 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 843 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 844 | memcpy(header->signature, "RSDT", 4); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 845 | memcpy(header->oem_id, oem_id, 6); |
| 846 | memcpy(header->oem_table_id, oem_table_id, 8); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 847 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 848 | |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 849 | header->length = sizeof(acpi_rsdt_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 850 | header->revision = get_acpi_table_revision(RSDT); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 851 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 852 | /* Entries are filled in later, we come with an empty set. */ |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 853 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 854 | /* Fix checksum. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 855 | header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 858 | static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id) |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 859 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 860 | acpi_header_t *header = &(xsdt->header); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 861 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 862 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 863 | memcpy(header->signature, "XSDT", 4); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 864 | memcpy(header->oem_id, oem_id, 6); |
| 865 | memcpy(header->oem_table_id, oem_table_id, 8); |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 866 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 867 | |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 868 | header->length = sizeof(acpi_xsdt_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 869 | header->revision = get_acpi_table_revision(XSDT); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 870 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 871 | /* Entries are filled in later, we come with an empty set. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 872 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 873 | /* Fix checksum. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 874 | header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t)); |
| 875 | } |
| 876 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 877 | static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt, |
| 878 | acpi_xsdt_t *xsdt, char *oem_id) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 879 | { |
Stefan Reinauer | d18faac | 2009-11-05 18:06:43 +0000 | [diff] [blame] | 880 | memset(rsdp, 0, sizeof(acpi_rsdp_t)); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 881 | |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 882 | memcpy(rsdp->signature, RSDP_SIG, 8); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 883 | memcpy(rsdp->oem_id, oem_id, 6); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 884 | |
| 885 | rsdp->length = sizeof(acpi_rsdp_t); |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 886 | rsdp->rsdt_address = (uintptr_t)rsdt; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 887 | |
| 888 | /* |
| 889 | * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2. |
| 890 | * |
| 891 | * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2. |
| 892 | * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR |
| 893 | * revision 0). |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 894 | */ |
| 895 | if (xsdt == NULL) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 896 | rsdp->revision = 0; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 897 | } else { |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 898 | rsdp->xsdt_address = (u64)(uintptr_t)xsdt; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 899 | rsdp->revision = get_acpi_table_revision(RSDP); |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 900 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 901 | |
| 902 | /* Calculate checksums. */ |
| 903 | rsdp->checksum = acpi_checksum((void *)rsdp, 20); |
| 904 | rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 905 | } |
| 906 | |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 907 | unsigned long acpi_create_hest_error_source(acpi_hest_t *hest, |
| 908 | acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len) |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 909 | { |
| 910 | acpi_header_t *header = &(hest->header); |
| 911 | acpi_hest_hen_t *hen; |
| 912 | void *pos; |
| 913 | u16 len; |
| 914 | |
| 915 | pos = esd; |
| 916 | memset(pos, 0, sizeof(acpi_hest_esd_t)); |
| 917 | len = 0; |
| 918 | esd->type = type; /* MCE */ |
| 919 | esd->source_id = hest->error_source_count; |
| 920 | esd->flags = 0; /* FIRMWARE_FIRST */ |
| 921 | esd->enabled = 1; |
| 922 | esd->prealloc_erecords = 1; |
| 923 | esd->max_section_per_record = 0x1; |
| 924 | |
| 925 | len += sizeof(acpi_hest_esd_t); |
| 926 | pos = esd + 1; |
| 927 | |
| 928 | switch (type) { |
| 929 | case 0: /* MCE */ |
| 930 | break; |
| 931 | case 1: /* CMC */ |
| 932 | hen = (acpi_hest_hen_t *) (pos); |
| 933 | memset(pos, 0, sizeof(acpi_hest_hen_t)); |
| 934 | hen->type = 3; /* SCI? */ |
| 935 | hen->length = sizeof(acpi_hest_hen_t); |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 936 | hen->conf_we = 0; /* Configuration Write Enable. */ |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 937 | hen->poll_interval = 0; |
| 938 | hen->vector = 0; |
| 939 | hen->sw2poll_threshold_val = 0; |
| 940 | hen->sw2poll_threshold_win = 0; |
| 941 | hen->error_threshold_val = 0; |
| 942 | hen->error_threshold_win = 0; |
| 943 | len += sizeof(acpi_hest_hen_t); |
| 944 | pos = hen + 1; |
| 945 | break; |
| 946 | case 2: /* NMI */ |
| 947 | case 6: /* AER Root Port */ |
| 948 | case 7: /* AER Endpoint */ |
| 949 | case 8: /* AER Bridge */ |
| 950 | case 9: /* Generic Hardware Error Source. */ |
| 951 | /* TODO: */ |
| 952 | break; |
| 953 | default: |
| 954 | printk(BIOS_DEBUG, "Invalid type of Error Source."); |
| 955 | break; |
| 956 | } |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 957 | hest->error_source_count++; |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 958 | |
| 959 | memcpy(pos, data, data_len); |
| 960 | len += data_len; |
| 961 | header->length += len; |
| 962 | |
| 963 | return len; |
| 964 | } |
| 965 | |
| 966 | /* ACPI 4.0 */ |
Vladimir Serbinenko | 807127f | 2014-11-09 13:36:18 +0100 | [diff] [blame] | 967 | void acpi_write_hest(acpi_hest_t *hest, |
| 968 | unsigned long (*acpi_fill_hest)(acpi_hest_t *hest)) |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 969 | { |
| 970 | acpi_header_t *header = &(hest->header); |
| 971 | |
| 972 | memset(hest, 0, sizeof(acpi_hest_t)); |
| 973 | |
| 974 | memcpy(header->signature, "HEST", 4); |
| 975 | memcpy(header->oem_id, OEM_ID, 6); |
| 976 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 977 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 978 | header->length += sizeof(acpi_hest_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 979 | header->revision = get_acpi_table_revision(HEST); |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 980 | |
| 981 | acpi_fill_hest(hest); |
| 982 | |
| 983 | /* Calculate checksums. */ |
| 984 | header->checksum = acpi_checksum((void *)hest, header->length); |
| 985 | } |
| 986 | |
Marshall Dawson | 1d8d369 | 2018-09-04 13:45:26 -0600 | [diff] [blame] | 987 | /* ACPI 3.0b */ |
| 988 | void acpi_write_bert(acpi_bert_t *bert, uintptr_t region, size_t length) |
| 989 | { |
| 990 | acpi_header_t *header = &(bert->header); |
| 991 | |
| 992 | memset(bert, 0, sizeof(acpi_bert_t)); |
| 993 | |
| 994 | memcpy(header->signature, "BERT", 4); |
| 995 | memcpy(header->oem_id, OEM_ID, 6); |
| 996 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 997 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 998 | header->length += sizeof(acpi_bert_t); |
| 999 | header->revision = get_acpi_table_revision(BERT); |
| 1000 | |
| 1001 | bert->error_region = region; |
| 1002 | bert->region_length = length; |
| 1003 | |
| 1004 | /* Calculate checksums. */ |
| 1005 | header->checksum = acpi_checksum((void *)bert, header->length); |
| 1006 | } |
| 1007 | |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1008 | #if IS_ENABLED(CONFIG_COMMON_FADT) |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 1009 | void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt) |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1010 | { |
| 1011 | acpi_header_t *header = &(fadt->header); |
| 1012 | |
| 1013 | memset((void *) fadt, 0, sizeof(acpi_fadt_t)); |
| 1014 | memcpy(header->signature, "FACP", 4); |
| 1015 | header->length = sizeof(acpi_fadt_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1016 | header->revision = get_acpi_table_revision(FADT); |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1017 | memcpy(header->oem_id, OEM_ID, 6); |
| 1018 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 1019 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 1020 | header->asl_compiler_revision = 0; |
| 1021 | |
| 1022 | fadt->firmware_ctrl = (unsigned long) facs; |
| 1023 | fadt->dsdt = (unsigned long) dsdt; |
| 1024 | |
| 1025 | fadt->x_firmware_ctl_l = (unsigned long)facs; |
| 1026 | fadt->x_firmware_ctl_h = 0; |
| 1027 | fadt->x_dsdt_l = (unsigned long)dsdt; |
| 1028 | fadt->x_dsdt_h = 0; |
| 1029 | |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 1030 | if (IS_ENABLED(CONFIG_SYSTEM_TYPE_LAPTOP)) |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1031 | fadt->preferred_pm_profile = PM_MOBILE; |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 1032 | else |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1033 | fadt->preferred_pm_profile = PM_DESKTOP; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1034 | |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 1035 | acpi_fill_fadt(fadt); |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1036 | |
| 1037 | header->checksum = |
| 1038 | acpi_checksum((void *) fadt, header->length); |
| 1039 | } |
| 1040 | #endif |
| 1041 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 1042 | unsigned long __weak fw_cfg_acpi_tables(unsigned long start) |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 1043 | { |
| 1044 | return 0; |
| 1045 | } |
| 1046 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1047 | unsigned long write_acpi_tables(unsigned long start) |
| 1048 | { |
| 1049 | unsigned long current; |
| 1050 | acpi_rsdp_t *rsdp; |
| 1051 | acpi_rsdt_t *rsdt; |
| 1052 | acpi_xsdt_t *xsdt; |
| 1053 | acpi_fadt_t *fadt; |
| 1054 | acpi_facs_t *facs; |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1055 | acpi_header_t *slic_file, *slic; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1056 | acpi_header_t *ssdt; |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1057 | acpi_header_t *dsdt_file, *dsdt; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1058 | acpi_mcfg_t *mcfg; |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 1059 | acpi_tcpa_t *tcpa; |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 1060 | acpi_tpm2_t *tpm2; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1061 | acpi_madt_t *madt; |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 1062 | struct device *dev; |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 1063 | unsigned long fw; |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1064 | size_t slic_size, dsdt_size; |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1065 | char oem_id[6], oem_table_id[8]; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1066 | |
| 1067 | current = start; |
| 1068 | |
| 1069 | /* Align ACPI tables to 16byte */ |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1070 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1071 | |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 1072 | fw = fw_cfg_acpi_tables(current); |
| 1073 | if (fw) |
| 1074 | return fw; |
| 1075 | |
Vladimir Serbinenko | a4cf83d | 2015-06-02 21:40:29 +0200 | [diff] [blame] | 1076 | dsdt_file = cbfs_boot_map_with_leak( |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1077 | CONFIG_CBFS_PREFIX "/dsdt.aml", |
| 1078 | CBFS_TYPE_RAW, &dsdt_size); |
| 1079 | if (!dsdt_file) { |
| 1080 | printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n"); |
| 1081 | return current; |
| 1082 | } |
| 1083 | |
| 1084 | if (dsdt_file->length > dsdt_size |
Elyes HAOUAS | 7d87e76 | 2016-10-03 22:11:07 +0200 | [diff] [blame] | 1085 | || dsdt_file->length < sizeof(acpi_header_t) |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1086 | || memcmp(dsdt_file->signature, "DSDT", 4) != 0) { |
| 1087 | printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n"); |
| 1088 | return current; |
| 1089 | } |
| 1090 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 1091 | slic_file = cbfs_boot_map_with_leak(CONFIG_CBFS_PREFIX "/slic", |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1092 | CBFS_TYPE_RAW, &slic_size); |
Vladimir Serbinenko | 2cb2978 | 2015-05-31 11:32:09 +0200 | [diff] [blame] | 1093 | if (slic_file |
| 1094 | && (slic_file->length > slic_size |
Elyes HAOUAS | 7d87e76 | 2016-10-03 22:11:07 +0200 | [diff] [blame] | 1095 | || slic_file->length < sizeof(acpi_header_t) |
Vladimir Serbinenko | 2cb2978 | 2015-05-31 11:32:09 +0200 | [diff] [blame] | 1096 | || memcmp(slic_file->signature, "SLIC", 4) != 0)) { |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1097 | slic_file = 0; |
| 1098 | } |
| 1099 | |
| 1100 | if (slic_file) { |
| 1101 | memcpy(oem_id, slic_file->oem_id, 6); |
| 1102 | memcpy(oem_table_id, slic_file->oem_table_id, 8); |
| 1103 | } else { |
| 1104 | memcpy(oem_id, OEM_ID, 6); |
| 1105 | memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 1106 | } |
| 1107 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1108 | printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start); |
| 1109 | |
| 1110 | /* We need at least an RSDP and an RSDT Table */ |
| 1111 | rsdp = (acpi_rsdp_t *) current; |
| 1112 | current += sizeof(acpi_rsdp_t); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1113 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1114 | rsdt = (acpi_rsdt_t *) current; |
| 1115 | current += sizeof(acpi_rsdt_t); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1116 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1117 | xsdt = (acpi_xsdt_t *) current; |
| 1118 | current += sizeof(acpi_xsdt_t); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1119 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1120 | |
| 1121 | /* clear all table memory */ |
| 1122 | memset((void *) start, 0, current - start); |
| 1123 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1124 | acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id); |
| 1125 | acpi_write_rsdt(rsdt, oem_id, oem_table_id); |
| 1126 | acpi_write_xsdt(xsdt, oem_id, oem_table_id); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1127 | |
| 1128 | printk(BIOS_DEBUG, "ACPI: * FACS\n"); |
Patrick Georgi | 133108a | 2015-08-08 23:20:58 +0200 | [diff] [blame] | 1129 | current = (ALIGN(current, 64)); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1130 | facs = (acpi_facs_t *) current; |
| 1131 | current += sizeof(acpi_facs_t); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1132 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1133 | acpi_create_facs(facs); |
| 1134 | |
| 1135 | printk(BIOS_DEBUG, "ACPI: * DSDT\n"); |
| 1136 | dsdt = (acpi_header_t *) current; |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1137 | memcpy(dsdt, dsdt_file, sizeof(acpi_header_t)); |
Vladimir Serbinenko | 334fd8e | 2014-10-05 11:10:35 +0200 | [diff] [blame] | 1138 | if (dsdt->length >= sizeof(acpi_header_t)) { |
| 1139 | current += sizeof(acpi_header_t); |
| 1140 | |
| 1141 | acpigen_set_current((char *) current); |
| 1142 | for (dev = all_devices; dev; dev = dev->next) |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 1143 | if (dev->ops && dev->ops->acpi_inject_dsdt_generator) |
Alexander Couzens | a90dad1 | 2015-04-12 21:49:46 +0200 | [diff] [blame] | 1144 | dev->ops->acpi_inject_dsdt_generator(dev); |
Vladimir Serbinenko | 334fd8e | 2014-10-05 11:10:35 +0200 | [diff] [blame] | 1145 | current = (unsigned long) acpigen_get_current(); |
| 1146 | memcpy((char *)current, |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1147 | (char *)dsdt_file + sizeof(acpi_header_t), |
Vladimir Serbinenko | 334fd8e | 2014-10-05 11:10:35 +0200 | [diff] [blame] | 1148 | dsdt->length - sizeof(acpi_header_t)); |
| 1149 | current += dsdt->length - sizeof(acpi_header_t); |
| 1150 | |
| 1151 | /* (Re)calculate length and checksum. */ |
| 1152 | dsdt->length = current - (unsigned long)dsdt; |
| 1153 | dsdt->checksum = 0; |
| 1154 | dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length); |
| 1155 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1156 | |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1157 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1158 | |
| 1159 | printk(BIOS_DEBUG, "ACPI: * FADT\n"); |
| 1160 | fadt = (acpi_fadt_t *) current; |
| 1161 | current += sizeof(acpi_fadt_t); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1162 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1163 | |
| 1164 | acpi_create_fadt(fadt, facs, dsdt); |
| 1165 | acpi_add_table(rsdp, fadt); |
| 1166 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1167 | if (slic_file) { |
| 1168 | printk(BIOS_DEBUG, "ACPI: * SLIC\n"); |
| 1169 | slic = (acpi_header_t *)current; |
| 1170 | memcpy(slic, slic_file, slic_file->length); |
| 1171 | current += slic_file->length; |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1172 | current = acpi_align_current(current); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1173 | acpi_add_table(rsdp, slic); |
| 1174 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1175 | |
| 1176 | printk(BIOS_DEBUG, "ACPI: * SSDT\n"); |
| 1177 | ssdt = (acpi_header_t *)current; |
| 1178 | acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR); |
Vladimir Serbinenko | 9310df8 | 2014-10-10 20:40:41 +0200 | [diff] [blame] | 1179 | if (ssdt->length > sizeof(acpi_header_t)) { |
| 1180 | current += ssdt->length; |
| 1181 | acpi_add_table(rsdp, ssdt); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1182 | current = acpi_align_current(current); |
Vladimir Serbinenko | 9310df8 | 2014-10-10 20:40:41 +0200 | [diff] [blame] | 1183 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1184 | |
| 1185 | printk(BIOS_DEBUG, "ACPI: * MCFG\n"); |
| 1186 | mcfg = (acpi_mcfg_t *) current; |
| 1187 | acpi_create_mcfg(mcfg); |
| 1188 | if (mcfg->header.length > sizeof(acpi_mcfg_t)) { |
| 1189 | current += mcfg->header.length; |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1190 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1191 | acpi_add_table(rsdp, mcfg); |
| 1192 | } |
| 1193 | |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 1194 | if (IS_ENABLED(CONFIG_TPM1)) { |
| 1195 | printk(BIOS_DEBUG, "ACPI: * TCPA\n"); |
| 1196 | tcpa = (acpi_tcpa_t *) current; |
| 1197 | acpi_create_tcpa(tcpa); |
| 1198 | if (tcpa->header.length >= sizeof(acpi_tcpa_t)) { |
| 1199 | current += tcpa->header.length; |
| 1200 | current = acpi_align_current(current); |
| 1201 | acpi_add_table(rsdp, tcpa); |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | if (IS_ENABLED(CONFIG_TPM2)) { |
| 1206 | printk(BIOS_DEBUG, "ACPI: * TPM2\n"); |
| 1207 | tpm2 = (acpi_tpm2_t *) current; |
| 1208 | acpi_create_tpm2(tpm2); |
| 1209 | if (tpm2->header.length >= sizeof(acpi_tpm2_t)) { |
| 1210 | current += tpm2->header.length; |
| 1211 | current = acpi_align_current(current); |
| 1212 | acpi_add_table(rsdp, tpm2); |
| 1213 | } |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 1214 | } |
| 1215 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1216 | printk(BIOS_DEBUG, "ACPI: * MADT\n"); |
| 1217 | |
| 1218 | madt = (acpi_madt_t *) current; |
| 1219 | acpi_create_madt(madt); |
| 1220 | if (madt->header.length > sizeof(acpi_madt_t)) { |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 1221 | current += madt->header.length; |
| 1222 | acpi_add_table(rsdp, madt); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1223 | } |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1224 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1225 | |
| 1226 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 1227 | |
| 1228 | for (dev = all_devices; dev; dev = dev->next) { |
| 1229 | if (dev->ops && dev->ops->write_acpi_tables) { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 1230 | current = dev->ops->write_acpi_tables(dev, current, |
| 1231 | rsdp); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1232 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | printk(BIOS_INFO, "ACPI: done.\n"); |
| 1237 | return current; |
| 1238 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1239 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1240 | static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp) |
| 1241 | { |
| 1242 | if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0) |
| 1243 | return NULL; |
| 1244 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1245 | printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1246 | |
| 1247 | if (acpi_checksum((void *)rsdp, 20) != 0) |
| 1248 | return NULL; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1249 | printk(BIOS_DEBUG, "Checksum 1 passed\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1250 | |
| 1251 | if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp, |
| 1252 | rsdp->length) != 0)) |
| 1253 | return NULL; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1254 | printk(BIOS_DEBUG, "Checksum 2 passed all OK\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1255 | |
| 1256 | return rsdp; |
| 1257 | } |
| 1258 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1259 | void *acpi_find_wakeup_vector(void) |
| 1260 | { |
| 1261 | char *p, *end; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1262 | acpi_rsdt_t *rsdt; |
| 1263 | acpi_facs_t *facs; |
Martin Roth | c5f4926 | 2012-12-14 19:17:55 -0700 | [diff] [blame] | 1264 | acpi_fadt_t *fadt = NULL; |
Kyösti Mälkki | 072d436b | 2016-06-17 08:44:40 +0300 | [diff] [blame] | 1265 | acpi_rsdp_t *rsdp = NULL; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1266 | void *wake_vec; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1267 | int i; |
| 1268 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1269 | if (!acpi_is_wakeup()) |
| 1270 | return NULL; |
| 1271 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1272 | printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1273 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1274 | /* Find RSDP. */ |
| 1275 | for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) { |
Lee Leahy | 0b5678f | 2017-03-16 16:01:40 -0700 | [diff] [blame] | 1276 | rsdp = valid_rsdp((acpi_rsdp_t *)p); |
| 1277 | if (rsdp) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1278 | break; |
| 1279 | } |
| 1280 | |
| 1281 | if (rsdp == NULL) |
| 1282 | return NULL; |
| 1283 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1284 | printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp); |
Stefan Reinauer | 71a3018 | 2015-07-30 16:28:13 -0700 | [diff] [blame] | 1285 | rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 1286 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1287 | end = (char *)rsdt + rsdt->header.length; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1288 | 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] | 1289 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1290 | for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) { |
Stefan Reinauer | 71a3018 | 2015-07-30 16:28:13 -0700 | [diff] [blame] | 1291 | fadt = (acpi_fadt_t *)(uintptr_t)rsdt->entry[i]; |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 1292 | if (strncmp((char *)fadt, "FACP", 4) == 0) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1293 | break; |
| 1294 | fadt = NULL; |
| 1295 | } |
| 1296 | |
| 1297 | if (fadt == NULL) |
| 1298 | return NULL; |
| 1299 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1300 | printk(BIOS_DEBUG, "FADT found at %p\n", fadt); |
Stefan Reinauer | 71a3018 | 2015-07-30 16:28:13 -0700 | [diff] [blame] | 1301 | facs = (acpi_facs_t *)(uintptr_t)fadt->firmware_ctrl; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1302 | |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 1303 | if (facs == NULL) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1304 | printk(BIOS_DEBUG, "No FACS found, wake up from S3 not " |
| 1305 | "possible.\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1306 | return NULL; |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 1307 | } |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1308 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1309 | printk(BIOS_DEBUG, "FACS found at %p\n", facs); |
Stefan Reinauer | 71a3018 | 2015-07-30 16:28:13 -0700 | [diff] [blame] | 1310 | wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1311 | printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1312 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1313 | return wake_vec; |
| 1314 | } |
| 1315 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 1316 | __weak int acpi_get_gpe(int gpe) |
Duncan Laurie | 1f6e681 | 2016-09-19 12:04:19 -0700 | [diff] [blame] | 1317 | { |
| 1318 | return -1; /* implemented by SOC */ |
| 1319 | } |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1320 | |
| 1321 | int get_acpi_table_revision(enum acpi_tables table) |
| 1322 | { |
| 1323 | switch (table) { |
| 1324 | case FADT: |
| 1325 | return ACPI_FADT_REV_ACPI_3_0; |
| 1326 | case MADT: /* ACPI 1.0/2.0: 1, ACPI 3.0: 2, ACPI 4.0: 3 */ |
Marc Jones | 4ddd476 | 2018-08-21 10:50:57 -0600 | [diff] [blame] | 1327 | return 2; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1328 | case MCFG: |
| 1329 | return 1; |
| 1330 | case TCPA: |
| 1331 | return 2; |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 1332 | case TPM2: |
| 1333 | return 4; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1334 | case SSDT: /* ACPI 1.0/2.0: ?, ACPI 3.0/4.0: 2 */ |
| 1335 | return 2; |
| 1336 | case SRAT: /* ACPI 1.0: N/A, 2.0: 1, 3.0: 2, 4.0: 3 */ |
| 1337 | return 1; /* TODO Should probably be upgraded to 2 */ |
| 1338 | case DMAR: |
| 1339 | return 1; |
| 1340 | case SLIT: /* ACPI 1.0: N/A, ACPI 2.0/3.0/4.0: 1 */ |
| 1341 | return 1; |
| 1342 | case HPET: /* Currently 1. Table added in ACPI 2.0. */ |
| 1343 | return 1; |
| 1344 | case VFCT: /* ACPI 1.0: N/A, ACPI 2.0/3.0/4.0: 1 */ |
| 1345 | return 1; |
| 1346 | case IVRS: |
| 1347 | return IVRS_FORMAT_FIXED; |
| 1348 | case DBG2: |
| 1349 | return 0; |
| 1350 | case FACS: /* ACPI 1.0: 0, ACPI 2.0/3.0: 1, ACPI 4.0: 2 */ |
| 1351 | return 1; |
| 1352 | case RSDT: /* ACPI 1.0/2.0/3.0/4.0: 1 */ |
| 1353 | return 1; |
| 1354 | case XSDT: /* ACPI 1.0: N/A, 2.0/3.0/4.0: 1 */ |
| 1355 | return 1; |
| 1356 | case RSDP: /* ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2. */ |
| 1357 | return 2; |
| 1358 | case HEST: |
| 1359 | return 1; |
| 1360 | case NHLT: |
| 1361 | return 5; |
Marshall Dawson | 44705c6 | 2018-09-04 13:47:15 -0600 | [diff] [blame] | 1362 | case BERT: |
| 1363 | return 1; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1364 | default: |
| 1365 | return -1; |
| 1366 | } |
| 1367 | return -1; |
| 1368 | } |