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