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