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