Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 2 | /* |
Martin Roth | 20bbd81 | 2019-08-30 21:09:37 -0600 | [diff] [blame] | 3 | * coreboot ACPI Table support |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 6 | /* |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 7 | * Each system port implementing ACPI has to provide two functions: |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 8 | * |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 9 | * write_acpi_tables() |
| 10 | * acpi_dump_apics() |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 11 | * |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 12 | * See Kontron 986LCD-M port for a good example of an ACPI implementation |
| 13 | * in coreboot. |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 14 | */ |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 15 | |
| 16 | #include <console/console.h> |
| 17 | #include <string.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 18 | #include <acpi/acpi.h> |
| 19 | #include <acpi/acpi_ivrs.h> |
| 20 | #include <acpi/acpigen.h> |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 21 | #include <device/pci.h> |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 22 | #include <cbmem.h> |
Elyes HAOUAS | e2d152c | 2019-06-21 07:06:50 +0200 | [diff] [blame] | 23 | #include <commonlib/helpers.h> |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 24 | #include <cpu/cpu.h> |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 25 | #include <cbfs.h> |
Elyes HAOUAS | cdd2f63 | 2021-02-11 19:37:11 +0100 | [diff] [blame] | 26 | #include <types.h> |
Elyes HAOUAS | 26071aa | 2019-02-15 08:21:33 +0100 | [diff] [blame] | 27 | #include <version.h> |
Werner Zeh | db561e6 | 2019-02-19 13:39:56 +0100 | [diff] [blame] | 28 | #include <commonlib/sort.h> |
Nico Huber | d581137 | 2021-07-12 18:11:58 +0200 | [diff] [blame] | 29 | #include <pc80/mc146818rtc.h> |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 30 | |
Patrick Rudolph | cfe08ff | 2019-09-10 15:40:47 +0200 | [diff] [blame] | 31 | static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp); |
| 32 | |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 33 | u8 acpi_checksum(u8 *table, u32 length) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 34 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 35 | u8 ret = 0; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 36 | while (length--) { |
| 37 | ret += *table; |
| 38 | table++; |
| 39 | } |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 40 | return -ret; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 43 | /** |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 44 | * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length |
| 45 | * and checksum. |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 46 | */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 47 | void acpi_add_table(acpi_rsdp_t *rsdp, void *table) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 48 | { |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 49 | int i, entries_num; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 50 | acpi_rsdt_t *rsdt; |
| 51 | acpi_xsdt_t *xsdt = NULL; |
| 52 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 53 | /* The RSDT is mandatory... */ |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 54 | rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 55 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 56 | /* ...while the XSDT is not. */ |
| 57 | if (rsdp->xsdt_address) |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 58 | xsdt = (acpi_xsdt_t *)((uintptr_t)rsdp->xsdt_address); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 59 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 60 | /* This should always be MAX_ACPI_TABLES. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 61 | entries_num = ARRAY_SIZE(rsdt->entry); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 62 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 63 | for (i = 0; i < entries_num; i++) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 64 | if (rsdt->entry[i] == 0) |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 65 | break; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 68 | if (i >= entries_num) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 69 | 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] | 70 | "too many tables.\n"); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 71 | return; |
| 72 | } |
| 73 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 74 | /* Add table to the RSDT. */ |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 75 | rsdt->entry[i] = (uintptr_t)table; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 76 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 77 | /* Fix RSDT length or the kernel will assume invalid entries. */ |
| 78 | rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i + 1)); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 79 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 80 | /* Re-calculate checksum. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 81 | rsdt->header.checksum = 0; /* Hope this won't get optimized away */ |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 82 | rsdt->header.checksum = acpi_checksum((u8 *)rsdt, rsdt->header.length); |
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 | /* |
| 85 | * 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] | 86 | * now we want the XSDT and RSDT to always be in sync in coreboot. |
| 87 | */ |
| 88 | if (xsdt) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 89 | /* Add table to the XSDT. */ |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 90 | xsdt->entry[i] = (u64)(uintptr_t)table; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 91 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 92 | /* Fix XSDT length. */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 93 | xsdt->header.length = sizeof(acpi_header_t) + |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 94 | (sizeof(u64) * (i + 1)); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 95 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 96 | /* Re-calculate checksum. */ |
| 97 | xsdt->header.checksum = 0; |
| 98 | xsdt->header.checksum = acpi_checksum((u8 *)xsdt, |
Cristian Măgherușan-Stanciu | ba48281 | 2011-07-02 00:57:07 +0300 | [diff] [blame] | 99 | xsdt->header.length); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 102 | 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] | 103 | i + 1, entries_num, rsdt->header.length); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 106 | 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] | 107 | u16 seg_nr, u8 start, u8 end) |
Stefan Reinauer | 26d431a | 2009-01-20 19:17:51 +0000 | [diff] [blame] | 108 | { |
Vladimir Serbinenko | 60fccdc | 2014-10-05 11:05:16 +0200 | [diff] [blame] | 109 | memset(mmconfig, 0, sizeof(*mmconfig)); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 110 | mmconfig->base_address = base; |
| 111 | mmconfig->base_reserved = 0; |
| 112 | mmconfig->pci_segment_group_number = seg_nr; |
| 113 | mmconfig->start_bus_number = start; |
| 114 | mmconfig->end_bus_number = end; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 115 | |
| 116 | return sizeof(acpi_mcfg_mmconfig_t); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 119 | 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] | 120 | { |
Himanshu Sahdev | 8c09b82 | 2019-10-21 18:50:50 +0530 | [diff] [blame] | 121 | lapic->type = LOCAL_APIC; /* Local APIC structure */ |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 122 | lapic->length = sizeof(acpi_madt_lapic_t); |
| 123 | lapic->flags = (1 << 0); /* Processor/LAPIC enabled */ |
| 124 | lapic->processor_id = cpu; |
| 125 | lapic->apic_id = apic; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 126 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 127 | return lapic->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Patrick Rudolph | 56a3ef2 | 2020-03-24 17:29:49 +0100 | [diff] [blame] | 130 | int acpi_create_madt_lx2apic(acpi_madt_lx2apic_t *lapic, u32 cpu, u32 apic) |
| 131 | { |
| 132 | lapic->type = LOCAL_X2APIC; /* Local APIC structure */ |
| 133 | lapic->reserved = 0; |
| 134 | lapic->length = sizeof(acpi_madt_lx2apic_t); |
| 135 | lapic->flags = (1 << 0); /* Processor/LAPIC enabled */ |
| 136 | lapic->processor_id = cpu; |
| 137 | lapic->x2apic_id = apic; |
| 138 | |
| 139 | return lapic->length; |
| 140 | } |
| 141 | |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 142 | unsigned long acpi_create_madt_lapics(unsigned long current) |
| 143 | { |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 144 | struct device *cpu; |
Werner Zeh | 423adfb | 2019-03-06 09:31:02 +0100 | [diff] [blame] | 145 | int index, apic_ids[CONFIG_MAX_CPUS] = {0}, num_cpus = 0; |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 146 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 147 | for (cpu = all_devices; cpu; cpu = cpu->next) { |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 148 | if ((cpu->path.type != DEVICE_PATH_APIC) || |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 149 | (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) { |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 150 | continue; |
| 151 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 152 | if (!cpu->enabled) |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 153 | continue; |
Werner Zeh | db561e6 | 2019-02-19 13:39:56 +0100 | [diff] [blame] | 154 | if (num_cpus >= ARRAY_SIZE(apic_ids)) |
| 155 | break; |
| 156 | apic_ids[num_cpus++] = cpu->path.apic.apic_id; |
| 157 | } |
Werner Zeh | fedb36e | 2019-03-12 07:07:50 +0100 | [diff] [blame] | 158 | if (num_cpus > 1) |
| 159 | bubblesort(apic_ids, num_cpus, NUM_ASCENDING); |
Werner Zeh | db561e6 | 2019-02-19 13:39:56 +0100 | [diff] [blame] | 160 | for (index = 0; index < num_cpus; index++) { |
Patrick Rudolph | 56a3ef2 | 2020-03-24 17:29:49 +0100 | [diff] [blame] | 161 | if (apic_ids[index] < 0xff) |
| 162 | current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, |
| 163 | index, apic_ids[index]); |
| 164 | else |
| 165 | current += acpi_create_madt_lx2apic((acpi_madt_lx2apic_t *)current, |
| 166 | index, apic_ids[index]); |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 167 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 168 | |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 169 | return current; |
| 170 | } |
| 171 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 172 | 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] | 173 | u32 gsi_base) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 174 | { |
Himanshu Sahdev | 8c09b82 | 2019-10-21 18:50:50 +0530 | [diff] [blame] | 175 | ioapic->type = IO_APIC; /* I/O APIC structure */ |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 176 | ioapic->length = sizeof(acpi_madt_ioapic_t); |
| 177 | ioapic->reserved = 0x00; |
| 178 | ioapic->gsi_base = gsi_base; |
| 179 | ioapic->ioapic_id = id; |
| 180 | ioapic->ioapic_addr = addr; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 181 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 182 | return ioapic->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 185 | int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride, |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 186 | u8 bus, u8 source, u32 gsirq, u16 flags) |
| 187 | { |
Himanshu Sahdev | 8c09b82 | 2019-10-21 18:50:50 +0530 | [diff] [blame] | 188 | irqoverride->type = IRQ_SOURCE_OVERRIDE; /* Interrupt source override */ |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 189 | irqoverride->length = sizeof(acpi_madt_irqoverride_t); |
| 190 | irqoverride->bus = bus; |
| 191 | irqoverride->source = source; |
| 192 | irqoverride->gsirq = gsirq; |
| 193 | irqoverride->flags = flags; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 194 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 195 | return irqoverride->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 198 | 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] | 199 | u16 flags, u8 lint) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 200 | { |
Himanshu Sahdev | 8c09b82 | 2019-10-21 18:50:50 +0530 | [diff] [blame] | 201 | lapic_nmi->type = LOCAL_APIC_NMI; /* Local APIC NMI structure */ |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 202 | lapic_nmi->length = sizeof(acpi_madt_lapic_nmi_t); |
| 203 | lapic_nmi->flags = flags; |
| 204 | lapic_nmi->processor_id = cpu; |
| 205 | lapic_nmi->lint = lint; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 206 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 207 | return lapic_nmi->length; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Patrick Rudolph | 56a3ef2 | 2020-03-24 17:29:49 +0100 | [diff] [blame] | 210 | int acpi_create_madt_lx2apic_nmi(acpi_madt_lx2apic_nmi_t *lapic_nmi, u32 cpu, |
| 211 | u16 flags, u8 lint) |
| 212 | { |
| 213 | lapic_nmi->type = LOCAL_X2APIC_NMI; /* Local APIC NMI structure */ |
| 214 | lapic_nmi->length = sizeof(acpi_madt_lx2apic_nmi_t); |
| 215 | lapic_nmi->flags = flags; |
| 216 | lapic_nmi->processor_id = cpu; |
| 217 | lapic_nmi->lint = lint; |
| 218 | lapic_nmi->reserved[0] = 0; |
| 219 | lapic_nmi->reserved[1] = 0; |
| 220 | lapic_nmi->reserved[2] = 0; |
| 221 | |
| 222 | return lapic_nmi->length; |
| 223 | } |
| 224 | |
Furquan Shaikh | b1859a6 | 2020-04-30 21:27:47 -0700 | [diff] [blame] | 225 | __weak uintptr_t cpu_get_lapic_addr(void) |
| 226 | { |
| 227 | /* |
| 228 | * If an architecture does not support LAPIC, this weak implementation returns LAPIC |
| 229 | * addr as 0. |
| 230 | */ |
| 231 | return 0; |
| 232 | } |
| 233 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 234 | void acpi_create_madt(acpi_madt_t *madt) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 235 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 236 | acpi_header_t *header = &(madt->header); |
| 237 | unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 238 | |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 239 | memset((void *)madt, 0, sizeof(acpi_madt_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, "APIC", 4); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +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); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +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; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 251 | header->length = sizeof(acpi_madt_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 252 | header->revision = get_acpi_table_revision(MADT); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 253 | |
Furquan Shaikh | b1859a6 | 2020-04-30 21:27:47 -0700 | [diff] [blame] | 254 | madt->lapic_addr = cpu_get_lapic_addr(); |
Nico Huber | 9df72e0 | 2018-11-24 18:25:50 +0100 | [diff] [blame] | 255 | if (CONFIG(ACPI_HAVE_PCAT_8259)) |
| 256 | madt->flags |= 1; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 257 | |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 258 | current = acpi_fill_madt(current); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 259 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 260 | /* (Re)calculate length and checksum. */ |
| 261 | header->length = current - (unsigned long)madt; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 262 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 263 | header->checksum = acpi_checksum((void *)madt, header->length); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Kyösti Mälkki | b54388d | 2021-02-14 15:09:45 +0200 | [diff] [blame] | 266 | static unsigned long acpi_fill_mcfg(unsigned long current) |
| 267 | { |
| 268 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current, |
Shelley Chen | 4e9bb33 | 2021-10-20 15:43:45 -0700 | [diff] [blame] | 269 | CONFIG_ECAM_MMCONF_BASE_ADDRESS, 0, 0, |
| 270 | CONFIG_ECAM_MMCONF_BUS_NUMBER - 1); |
Kyösti Mälkki | b54388d | 2021-02-14 15:09:45 +0200 | [diff] [blame] | 271 | return current; |
| 272 | } |
| 273 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 274 | /* MCFG is defined in the PCI Firmware Specification 3.0. */ |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 275 | void acpi_create_mcfg(acpi_mcfg_t *mcfg) |
| 276 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 277 | acpi_header_t *header = &(mcfg->header); |
| 278 | unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 279 | |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 280 | memset((void *)mcfg, 0, sizeof(acpi_mcfg_t)); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 281 | |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 282 | if (!header) |
| 283 | return; |
| 284 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 285 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 286 | memcpy(header->signature, "MCFG", 4); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 287 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 288 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 289 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 290 | |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 291 | header->asl_compiler_revision = asl_revision; |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 292 | header->length = sizeof(acpi_mcfg_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 293 | header->revision = get_acpi_table_revision(MCFG); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 294 | |
Shelley Chen | 4e9bb33 | 2021-10-20 15:43:45 -0700 | [diff] [blame] | 295 | if (CONFIG(ECAM_MMCONF_SUPPORT)) |
Kyösti Mälkki | b54388d | 2021-02-14 15:09:45 +0200 | [diff] [blame] | 296 | current = acpi_fill_mcfg(current); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 297 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 298 | /* (Re)calculate length and checksum. */ |
| 299 | header->length = current - (unsigned long)mcfg; |
| 300 | header->checksum = acpi_checksum((void *)mcfg, header->length); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 303 | static void *get_tcpa_log(u32 *size) |
| 304 | { |
| 305 | const struct cbmem_entry *ce; |
| 306 | const u32 tcpa_default_log_len = 0x10000; |
| 307 | void *lasa; |
Philipp Deppenwiese | 791ba97 | 2018-07-30 01:15:20 +0200 | [diff] [blame] | 308 | ce = cbmem_entry_find(CBMEM_ID_TCPA_TCG_LOG); |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 309 | if (ce) { |
| 310 | lasa = cbmem_entry_start(ce); |
| 311 | *size = cbmem_entry_size(ce); |
| 312 | printk(BIOS_DEBUG, "TCPA log found at %p\n", lasa); |
| 313 | return lasa; |
| 314 | } |
Philipp Deppenwiese | 791ba97 | 2018-07-30 01:15:20 +0200 | [diff] [blame] | 315 | lasa = cbmem_add(CBMEM_ID_TCPA_TCG_LOG, tcpa_default_log_len); |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 316 | if (!lasa) { |
| 317 | printk(BIOS_ERR, "TCPA log creation failed\n"); |
| 318 | return NULL; |
| 319 | } |
| 320 | |
| 321 | printk(BIOS_DEBUG, "TCPA log created at %p\n", lasa); |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 322 | memset(lasa, 0, tcpa_default_log_len); |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 323 | |
| 324 | *size = tcpa_default_log_len; |
| 325 | return lasa; |
| 326 | } |
| 327 | |
| 328 | static void acpi_create_tcpa(acpi_tcpa_t *tcpa) |
| 329 | { |
| 330 | acpi_header_t *header = &(tcpa->header); |
| 331 | u32 tcpa_log_len; |
| 332 | void *lasa; |
| 333 | |
| 334 | memset((void *)tcpa, 0, sizeof(acpi_tcpa_t)); |
| 335 | |
| 336 | lasa = get_tcpa_log(&tcpa_log_len); |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 337 | if (!lasa) |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 338 | return; |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 339 | |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 340 | if (!header) |
| 341 | return; |
| 342 | |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 343 | /* Fill out header fields. */ |
| 344 | memcpy(header->signature, "TCPA", 4); |
| 345 | memcpy(header->oem_id, OEM_ID, 6); |
| 346 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 347 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 348 | |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 349 | header->asl_compiler_revision = asl_revision; |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 350 | header->length = sizeof(acpi_tcpa_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 351 | header->revision = get_acpi_table_revision(TCPA); |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 352 | |
| 353 | tcpa->platform_class = 0; |
| 354 | tcpa->laml = tcpa_log_len; |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 355 | tcpa->lasa = (uintptr_t) lasa; |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 356 | |
| 357 | /* Calculate checksum. */ |
| 358 | header->checksum = acpi_checksum((void *)tcpa, header->length); |
| 359 | } |
| 360 | |
Michał Żygowski | 6e8692e | 2018-11-22 16:57:50 +0100 | [diff] [blame] | 361 | static void *get_tpm2_log(u32 *size) |
| 362 | { |
| 363 | const struct cbmem_entry *ce; |
| 364 | const u32 tpm2_default_log_len = 0x10000; |
| 365 | void *lasa; |
| 366 | ce = cbmem_entry_find(CBMEM_ID_TPM2_TCG_LOG); |
| 367 | if (ce) { |
| 368 | lasa = cbmem_entry_start(ce); |
| 369 | *size = cbmem_entry_size(ce); |
| 370 | printk(BIOS_DEBUG, "TPM2 log found at %p\n", lasa); |
| 371 | return lasa; |
| 372 | } |
| 373 | lasa = cbmem_add(CBMEM_ID_TPM2_TCG_LOG, tpm2_default_log_len); |
| 374 | if (!lasa) { |
| 375 | printk(BIOS_ERR, "TPM2 log creation failed\n"); |
| 376 | return NULL; |
| 377 | } |
| 378 | |
| 379 | printk(BIOS_DEBUG, "TPM2 log created at %p\n", lasa); |
| 380 | memset(lasa, 0, tpm2_default_log_len); |
| 381 | |
| 382 | *size = tpm2_default_log_len; |
| 383 | return lasa; |
| 384 | } |
| 385 | |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 386 | static void acpi_create_tpm2(acpi_tpm2_t *tpm2) |
| 387 | { |
| 388 | acpi_header_t *header = &(tpm2->header); |
Michał Żygowski | 6e8692e | 2018-11-22 16:57:50 +0100 | [diff] [blame] | 389 | u32 tpm2_log_len; |
| 390 | void *lasa; |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 391 | |
| 392 | memset((void *)tpm2, 0, sizeof(acpi_tpm2_t)); |
| 393 | |
Michał Żygowski | 6e8692e | 2018-11-22 16:57:50 +0100 | [diff] [blame] | 394 | /* |
| 395 | * Some payloads like SeaBIOS depend on log area to use TPM2. |
| 396 | * Get the memory size and address of TPM2 log area or initialize it. |
| 397 | */ |
| 398 | lasa = get_tpm2_log(&tpm2_log_len); |
| 399 | if (!lasa) |
| 400 | tpm2_log_len = 0; |
| 401 | |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 402 | if (!header) |
| 403 | return; |
| 404 | |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 405 | /* Fill out header fields. */ |
| 406 | memcpy(header->signature, "TPM2", 4); |
| 407 | memcpy(header->oem_id, OEM_ID, 6); |
| 408 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 409 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 410 | |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 411 | header->asl_compiler_revision = asl_revision; |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 412 | header->length = sizeof(acpi_tpm2_t); |
| 413 | header->revision = get_acpi_table_revision(TPM2); |
| 414 | |
| 415 | /* Hard to detect for coreboot. Just set it to 0 */ |
| 416 | tpm2->platform_class = 0; |
Christian Walter | 26e0d4c | 2019-07-14 15:47:23 +0200 | [diff] [blame] | 417 | if (CONFIG(CRB_TPM)) { |
| 418 | /* Must be set to 7 for CRB Support */ |
| 419 | tpm2->control_area = CONFIG_CRB_TPM_BASE_ADDRESS + 0x40; |
| 420 | tpm2->start_method = 7; |
| 421 | } else { |
| 422 | /* Must be set to 0 for FIFO interface support */ |
| 423 | tpm2->control_area = 0; |
| 424 | tpm2->start_method = 6; |
| 425 | } |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 426 | memset(tpm2->msp, 0, sizeof(tpm2->msp)); |
| 427 | |
Michał Żygowski | 6e8692e | 2018-11-22 16:57:50 +0100 | [diff] [blame] | 428 | /* Fill the log area size and start address fields. */ |
| 429 | tpm2->laml = tpm2_log_len; |
| 430 | tpm2->lasa = (uintptr_t) lasa; |
| 431 | |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 432 | /* Calculate checksum. */ |
| 433 | header->checksum = acpi_checksum((void *)tpm2, header->length); |
| 434 | } |
| 435 | |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 436 | static void acpi_ssdt_write_cbtable(void) |
| 437 | { |
| 438 | const struct cbmem_entry *cbtable; |
| 439 | uintptr_t base; |
| 440 | uint32_t size; |
| 441 | |
| 442 | cbtable = cbmem_entry_find(CBMEM_ID_CBTABLE); |
| 443 | if (!cbtable) |
| 444 | return; |
| 445 | base = (uintptr_t)cbmem_entry_start(cbtable); |
| 446 | size = cbmem_entry_size(cbtable); |
| 447 | |
| 448 | acpigen_write_device("CTBL"); |
| 449 | acpigen_write_coreboot_hid(COREBOOT_ACPI_ID_CBTABLE); |
| 450 | acpigen_write_name_integer("_UID", 0); |
David Wu | 5dff396 | 2018-03-21 16:48:53 +0800 | [diff] [blame] | 451 | acpigen_write_STA(ACPI_STATUS_DEVICE_HIDDEN_ON); |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 452 | acpigen_write_name("_CRS"); |
| 453 | acpigen_write_resourcetemplate_header(); |
| 454 | acpigen_write_mem32fixed(0, base, size); |
| 455 | acpigen_write_resourcetemplate_footer(); |
| 456 | acpigen_pop_len(); |
| 457 | } |
| 458 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 459 | 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] | 460 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 461 | unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t); |
| 462 | |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 463 | memset((void *)ssdt, 0, sizeof(acpi_header_t)); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 464 | |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 465 | memcpy(&ssdt->signature, "SSDT", 4); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 466 | ssdt->revision = get_acpi_table_revision(SSDT); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 467 | memcpy(&ssdt->oem_id, OEM_ID, 6); |
| 468 | memcpy(&ssdt->oem_table_id, oem_table_id, 8); |
| 469 | ssdt->oem_revision = 42; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 470 | memcpy(&ssdt->asl_compiler_id, ASLC, 4); |
Elyes HAOUAS | 26071aa | 2019-02-15 08:21:33 +0100 | [diff] [blame] | 471 | ssdt->asl_compiler_revision = asl_revision; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 472 | ssdt->length = sizeof(acpi_header_t); |
| 473 | |
Stefan Reinauer | 8dcd50b | 2009-03-06 17:24:29 +0000 | [diff] [blame] | 474 | acpigen_set_current((char *) current); |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 475 | |
| 476 | /* Write object to declare coreboot tables */ |
| 477 | acpi_ssdt_write_cbtable(); |
| 478 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 479 | { |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 480 | struct device *dev; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 481 | for (dev = all_devices; dev; dev = dev->next) |
Karthikeyan Ramasubramanian | d1c0f95 | 2020-11-02 16:26:52 -0700 | [diff] [blame] | 482 | if (dev->enabled && dev->ops && dev->ops->acpi_fill_ssdt) |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 483 | dev->ops->acpi_fill_ssdt(dev); |
Vladimir Serbinenko | 0a66991 | 2014-10-05 14:34:17 +0200 | [diff] [blame] | 484 | current = (unsigned long) acpigen_get_current(); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 485 | } |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 486 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 487 | /* (Re)calculate length and checksum. */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 488 | ssdt->length = current - (unsigned long)ssdt; |
| 489 | ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length); |
| 490 | } |
| 491 | |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 492 | int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic) |
| 493 | { |
Myles Watson | 0b4c9f0 | 2009-03-10 18:06:47 +0000 | [diff] [blame] | 494 | memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t)); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 495 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 496 | lapic->type = 0; /* Processor local APIC/SAPIC affinity structure */ |
| 497 | lapic->length = sizeof(acpi_srat_lapic_t); |
| 498 | lapic->flags = (1 << 0); /* Enabled (the use of this structure). */ |
| 499 | lapic->proximity_domain_7_0 = node; |
| 500 | /* TODO: proximity_domain_31_8, local SAPIC EID, clock domain. */ |
| 501 | lapic->apic_id = apic; |
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 | return lapic->length; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 506 | 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] | 507 | u32 flags) |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 508 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 509 | mem->type = 1; /* Memory affinity structure */ |
| 510 | mem->length = sizeof(acpi_srat_mem_t); |
| 511 | mem->base_address_low = (basek << 10); |
| 512 | mem->base_address_high = (basek >> (32 - 10)); |
| 513 | mem->length_low = (sizek << 10); |
| 514 | mem->length_high = (sizek >> (32 - 10)); |
| 515 | mem->proximity_domain = node; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 516 | mem->flags = flags; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 517 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 518 | return mem->length; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Jonathan Zhang | 3164b64 | 2021-04-21 17:51:31 -0700 | [diff] [blame] | 521 | int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain, |
| 522 | u16 seg, u8 bus, u8 dev, u8 func, u32 flags) |
| 523 | { |
| 524 | gia->type = ACPI_SRAT_STRUCTURE_GIA; |
| 525 | gia->length = sizeof(acpi_srat_gia_t); |
| 526 | gia->proximity_domain = proximity_domain; |
| 527 | gia->dev_handle_type = ACPI_SRAT_GIA_DEV_HANDLE_PCI; |
| 528 | /* First two bytes has segment number */ |
| 529 | memcpy(gia->dev_handle, &seg, 2); |
| 530 | gia->dev_handle[2] = bus; /* Byte 2 has bus number */ |
| 531 | /* Byte 3 has bits 7:3 for dev, bits 2:0 for func */ |
| 532 | gia->dev_handle[3] = PCI_SLOT(dev) | PCI_FUNC(func); |
| 533 | gia->flags = flags; |
| 534 | |
| 535 | return gia->length; |
| 536 | } |
| 537 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 538 | /* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */ |
Vladimir Serbinenko | 5e59757 | 2014-10-11 23:45:40 +0200 | [diff] [blame] | 539 | void acpi_create_srat(acpi_srat_t *srat, |
| 540 | unsigned long (*acpi_fill_srat)(unsigned long current)) |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 541 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 542 | acpi_header_t *header = &(srat->header); |
| 543 | unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 544 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 545 | memset((void *)srat, 0, sizeof(acpi_srat_t)); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 546 | |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 547 | if (!header) |
| 548 | return; |
| 549 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 550 | /* Fill out header fields. */ |
| 551 | memcpy(header->signature, "SRAT", 4); |
| 552 | memcpy(header->oem_id, OEM_ID, 6); |
| 553 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 554 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 555 | |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 556 | header->asl_compiler_revision = asl_revision; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 557 | header->length = sizeof(acpi_srat_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 558 | header->revision = get_acpi_table_revision(SRAT); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 559 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 560 | srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */ |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 561 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 562 | current = acpi_fill_srat(current); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 563 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 564 | /* (Re)calculate length and checksum. */ |
| 565 | header->length = current - (unsigned long)srat; |
| 566 | header->checksum = acpi_checksum((void *)srat, header->length); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Jonathan Zhang | 2a4e1f4 | 2021-04-01 11:43:37 -0700 | [diff] [blame] | 569 | int acpi_create_hmat_mpda(acpi_hmat_mpda_t *mpda, u32 initiator, u32 memory) |
| 570 | { |
| 571 | memset((void *)mpda, 0, sizeof(acpi_hmat_mpda_t)); |
| 572 | |
| 573 | mpda->type = 0; /* Memory Proximity Domain Attributes structure */ |
| 574 | mpda->length = sizeof(acpi_hmat_mpda_t); |
| 575 | /* |
| 576 | * Proximity Domain for Attached Initiator field is valid. |
| 577 | * Bit 1 and bit 2 are reserved since HMAT revision 2. |
| 578 | */ |
| 579 | mpda->flags = (1 << 0); |
| 580 | mpda->proximity_domain_initiator = initiator; |
| 581 | mpda->proximity_domain_memory = memory; |
| 582 | |
| 583 | return mpda->length; |
| 584 | } |
| 585 | |
| 586 | void acpi_create_hmat(acpi_hmat_t *hmat, |
| 587 | unsigned long (*acpi_fill_hmat)(unsigned long current)) |
| 588 | { |
| 589 | acpi_header_t *header = &(hmat->header); |
| 590 | unsigned long current = (unsigned long)hmat + sizeof(acpi_hmat_t); |
| 591 | |
| 592 | memset((void *)hmat, 0, sizeof(acpi_hmat_t)); |
| 593 | |
| 594 | if (!header) |
| 595 | return; |
| 596 | |
| 597 | /* Fill out header fields. */ |
| 598 | memcpy(header->signature, "HMAT", 4); |
| 599 | memcpy(header->oem_id, OEM_ID, 6); |
| 600 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 601 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 602 | |
| 603 | header->asl_compiler_revision = asl_revision; |
| 604 | header->length = sizeof(acpi_hmat_t); |
| 605 | header->revision = get_acpi_table_revision(HMAT); |
| 606 | |
| 607 | current = acpi_fill_hmat(current); |
| 608 | |
| 609 | /* (Re)calculate length and checksum. */ |
| 610 | header->length = current - (unsigned long)hmat; |
| 611 | header->checksum = acpi_checksum((void *)hmat, header->length); |
| 612 | } |
| 613 | |
Nico Huber | e561f35 | 2015-10-26 11:51:25 +0100 | [diff] [blame] | 614 | void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags, |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 615 | unsigned long (*acpi_fill_dmar)(unsigned long)) |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 616 | { |
| 617 | acpi_header_t *header = &(dmar->header); |
| 618 | unsigned long current = (unsigned long)dmar + sizeof(acpi_dmar_t); |
| 619 | |
| 620 | memset((void *)dmar, 0, sizeof(acpi_dmar_t)); |
| 621 | |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 622 | if (!header) |
| 623 | return; |
| 624 | |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 625 | /* Fill out header fields. */ |
| 626 | memcpy(header->signature, "DMAR", 4); |
| 627 | memcpy(header->oem_id, OEM_ID, 6); |
| 628 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 629 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 630 | |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 631 | header->asl_compiler_revision = asl_revision; |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 632 | header->length = sizeof(acpi_dmar_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 633 | header->revision = get_acpi_table_revision(DMAR); |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 634 | |
Jacob Laska | f3f654d | 2016-03-15 21:53:27 -0500 | [diff] [blame] | 635 | dmar->host_address_width = cpu_phys_address_size() - 1; |
Nico Huber | e561f35 | 2015-10-26 11:51:25 +0100 | [diff] [blame] | 636 | dmar->flags = flags; |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 637 | |
| 638 | current = acpi_fill_dmar(current); |
| 639 | |
| 640 | /* (Re)calculate length and checksum. */ |
| 641 | header->length = current - (unsigned long)dmar; |
| 642 | header->checksum = acpi_checksum((void *)dmar, header->length); |
| 643 | } |
| 644 | |
| 645 | unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags, |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 646 | u16 segment, u64 bar) |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 647 | { |
| 648 | dmar_entry_t *drhd = (dmar_entry_t *)current; |
| 649 | memset(drhd, 0, sizeof(*drhd)); |
| 650 | drhd->type = DMAR_DRHD; |
| 651 | drhd->length = sizeof(*drhd); /* will be fixed up later */ |
| 652 | drhd->flags = flags; |
| 653 | drhd->segment = segment; |
| 654 | drhd->bar = bar; |
| 655 | |
| 656 | return drhd->length; |
| 657 | } |
| 658 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 659 | unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment, |
| 660 | u64 bar, u64 limit) |
| 661 | { |
| 662 | dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)current; |
| 663 | memset(rmrr, 0, sizeof(*rmrr)); |
| 664 | rmrr->type = DMAR_RMRR; |
| 665 | rmrr->length = sizeof(*rmrr); /* will be fixed up later */ |
| 666 | rmrr->segment = segment; |
| 667 | rmrr->bar = bar; |
| 668 | rmrr->limit = limit; |
| 669 | |
| 670 | return rmrr->length; |
| 671 | } |
| 672 | |
Werner Zeh | d4d7695 | 2016-07-27 06:56:36 +0200 | [diff] [blame] | 673 | unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags, |
| 674 | u16 segment) |
| 675 | { |
| 676 | dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)current; |
| 677 | memset(atsr, 0, sizeof(*atsr)); |
| 678 | atsr->type = DMAR_ATSR; |
| 679 | atsr->length = sizeof(*atsr); /* will be fixed up later */ |
| 680 | atsr->flags = flags; |
| 681 | atsr->segment = segment; |
| 682 | |
| 683 | return atsr->length; |
| 684 | } |
| 685 | |
John Zhao | 76e7067 | 2019-04-04 11:03:28 -0700 | [diff] [blame] | 686 | unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr, |
| 687 | u32 proximity_domain) |
| 688 | { |
| 689 | dmar_rhsa_entry_t *rhsa = (dmar_rhsa_entry_t *)current; |
| 690 | memset(rhsa, 0, sizeof(*rhsa)); |
| 691 | rhsa->type = DMAR_RHSA; |
| 692 | rhsa->length = sizeof(*rhsa); |
| 693 | rhsa->base_address = base_addr; |
| 694 | rhsa->proximity_domain = proximity_domain; |
| 695 | |
| 696 | return rhsa->length; |
| 697 | } |
| 698 | |
| 699 | unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number, |
| 700 | const char *device_name) |
| 701 | { |
| 702 | dmar_andd_entry_t *andd = (dmar_andd_entry_t *)current; |
| 703 | int andd_len = sizeof(dmar_andd_entry_t) + strlen(device_name) + 1; |
| 704 | memset(andd, 0, andd_len); |
| 705 | andd->type = DMAR_ANDD; |
| 706 | andd->length = andd_len; |
| 707 | andd->device_number = device_number; |
| 708 | memcpy(&andd->device_name, device_name, strlen(device_name)); |
| 709 | |
| 710 | return andd->length; |
| 711 | } |
| 712 | |
John Zhao | 091532d | 2021-04-17 16:03:21 -0700 | [diff] [blame] | 713 | unsigned long acpi_create_dmar_satc(unsigned long current, u8 flags, u16 segment) |
John Zhao | 6edbb18 | 2021-03-24 11:55:09 -0700 | [diff] [blame] | 714 | { |
| 715 | dmar_satc_entry_t *satc = (dmar_satc_entry_t *)current; |
John Zhao | 091532d | 2021-04-17 16:03:21 -0700 | [diff] [blame] | 716 | int satc_len = sizeof(dmar_satc_entry_t); |
John Zhao | 6edbb18 | 2021-03-24 11:55:09 -0700 | [diff] [blame] | 717 | memset(satc, 0, satc_len); |
| 718 | satc->type = DMAR_SATC; |
| 719 | satc->length = satc_len; |
| 720 | satc->flags = flags; |
| 721 | satc->segment_number = segment; |
John Zhao | 6edbb18 | 2021-03-24 11:55:09 -0700 | [diff] [blame] | 722 | |
| 723 | return satc->length; |
| 724 | } |
| 725 | |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 726 | void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current) |
| 727 | { |
| 728 | dmar_entry_t *drhd = (dmar_entry_t *)base; |
| 729 | drhd->length = current - base; |
| 730 | } |
| 731 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 732 | void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current) |
| 733 | { |
| 734 | dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)base; |
| 735 | rmrr->length = current - base; |
| 736 | } |
| 737 | |
Werner Zeh | d4d7695 | 2016-07-27 06:56:36 +0200 | [diff] [blame] | 738 | void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current) |
| 739 | { |
| 740 | dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)base; |
| 741 | atsr->length = current - base; |
| 742 | } |
| 743 | |
John Zhao | 6edbb18 | 2021-03-24 11:55:09 -0700 | [diff] [blame] | 744 | void acpi_dmar_satc_fixup(unsigned long base, unsigned long current) |
| 745 | { |
| 746 | dmar_satc_entry_t *satc = (dmar_satc_entry_t *)base; |
| 747 | satc->length = current - base; |
| 748 | } |
| 749 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 750 | static unsigned long acpi_create_dmar_ds(unsigned long current, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 751 | 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] | 752 | { |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 753 | /* we don't support longer paths yet */ |
| 754 | const size_t dev_scope_length = sizeof(dev_scope_t) + 2; |
| 755 | |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 756 | dev_scope_t *ds = (dev_scope_t *)current; |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 757 | memset(ds, 0, dev_scope_length); |
| 758 | ds->type = type; |
| 759 | ds->length = dev_scope_length; |
| 760 | ds->enumeration = enumeration_id; |
| 761 | ds->start_bus = bus; |
| 762 | ds->path[0].dev = dev; |
| 763 | ds->path[0].fn = fn; |
Patrick Georgi | 3b590ff | 2012-09-11 15:21:01 +0200 | [diff] [blame] | 764 | |
| 765 | return ds->length; |
| 766 | } |
| 767 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 768 | 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] | 769 | u8 dev, u8 fn) |
| 770 | { |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 771 | return acpi_create_dmar_ds(current, |
Werner Zeh | 21a5bff | 2016-07-27 07:07:20 +0200 | [diff] [blame] | 772 | SCOPE_PCI_SUB, 0, bus, dev, fn); |
| 773 | } |
| 774 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 775 | unsigned long acpi_create_dmar_ds_pci(unsigned long current, u8 bus, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 776 | u8 dev, u8 fn) |
| 777 | { |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 778 | return acpi_create_dmar_ds(current, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 779 | SCOPE_PCI_ENDPOINT, 0, bus, dev, fn); |
| 780 | } |
| 781 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 782 | unsigned long acpi_create_dmar_ds_ioapic(unsigned long current, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 783 | u8 enumeration_id, u8 bus, u8 dev, u8 fn) |
| 784 | { |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 785 | return acpi_create_dmar_ds(current, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 786 | SCOPE_IOAPIC, enumeration_id, bus, dev, fn); |
| 787 | } |
| 788 | |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 789 | unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 790 | u8 enumeration_id, u8 bus, u8 dev, u8 fn) |
| 791 | { |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 792 | return acpi_create_dmar_ds(current, |
Nico Huber | 6c4751d | 2015-10-26 12:03:54 +0100 | [diff] [blame] | 793 | SCOPE_MSI_HPET, enumeration_id, bus, dev, fn); |
| 794 | } |
| 795 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 796 | /* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */ |
Vladimir Serbinenko | 5e59757 | 2014-10-11 23:45:40 +0200 | [diff] [blame] | 797 | void acpi_create_slit(acpi_slit_t *slit, |
| 798 | unsigned long (*acpi_fill_slit)(unsigned long current)) |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 799 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 800 | acpi_header_t *header = &(slit->header); |
| 801 | unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 802 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 803 | memset((void *)slit, 0, sizeof(acpi_slit_t)); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 804 | |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 805 | if (!header) |
| 806 | return; |
| 807 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 808 | /* Fill out header fields. */ |
| 809 | memcpy(header->signature, "SLIT", 4); |
| 810 | memcpy(header->oem_id, OEM_ID, 6); |
| 811 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 812 | memcpy(header->asl_compiler_id, ASLC, 4); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 813 | |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 814 | header->asl_compiler_revision = asl_revision; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 815 | header->length = sizeof(acpi_slit_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 816 | header->revision = get_acpi_table_revision(SLIT); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 817 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 818 | current = acpi_fill_slit(current); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 819 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 820 | /* (Re)calculate length and checksum. */ |
| 821 | header->length = current - (unsigned long)slit; |
| 822 | header->checksum = acpi_checksum((void *)slit, header->length); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 823 | } |
| 824 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 825 | /* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */ |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 826 | void acpi_create_hpet(acpi_hpet_t *hpet) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 827 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 828 | acpi_header_t *header = &(hpet->header); |
| 829 | acpi_addr_t *addr = &(hpet->addr); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 830 | |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 831 | memset((void *)hpet, 0, sizeof(acpi_hpet_t)); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 832 | |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 833 | if (!header) |
| 834 | return; |
| 835 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 836 | /* Fill out header fields. */ |
Stefan Reinauer | 4704dc5 | 2009-07-22 01:11:37 +0000 | [diff] [blame] | 837 | memcpy(header->signature, "HPET", 4); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 838 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 839 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 840 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 841 | |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 842 | header->asl_compiler_revision = asl_revision; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 843 | header->length = sizeof(acpi_hpet_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 844 | header->revision = get_acpi_table_revision(HPET); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 845 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 846 | /* Fill out HPET address. */ |
Elyes HAOUAS | 04071f4 | 2020-07-20 17:05:24 +0200 | [diff] [blame] | 847 | addr->space_id = ACPI_ADDRESS_SPACE_MEMORY; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 848 | addr->bit_width = 64; |
| 849 | addr->bit_offset = 0; |
Patrick Georgi | 9aeb694 | 2012-10-05 21:54:38 +0200 | [diff] [blame] | 850 | addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff; |
| 851 | addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 852 | |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 853 | hpet->id = *(unsigned int *)CONFIG_HPET_ADDRESS; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 854 | hpet->number = 0; |
Patrick Georgi | 9aeb694 | 2012-10-05 21:54:38 +0200 | [diff] [blame] | 855 | hpet->min_tick = CONFIG_HPET_MIN_TICKS; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 856 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 857 | header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 858 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 859 | |
Rocky Phagura | eff0713 | 2021-01-10 15:42:50 -0800 | [diff] [blame] | 860 | /* |
| 861 | * This method adds the ACPI error injection capability. It fills the default information. |
| 862 | * HW dependent code (caller) can modify the defaults upon return. If no changes are necessary |
| 863 | * and the defaults are acceptable then caller can simply add the table (acpi_add_table). |
| 864 | * INPUTS: |
| 865 | * einj - ptr to the starting location of EINJ table |
| 866 | * actions - number of actions to trigger an error (HW dependent) |
| 867 | * addr - address of trigger action table. This should be ACPI reserved memory and it will be |
| 868 | * shared between OS and FW. |
| 869 | */ |
| 870 | void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions) |
| 871 | { |
| 872 | int i; |
| 873 | acpi_header_t *header = &(einj->header); |
| 874 | acpi_injection_header_t *inj_header = &(einj->inj_header); |
| 875 | acpi_einj_smi_t *einj_smi = (acpi_einj_smi_t *)addr; |
| 876 | acpi_einj_trigger_table_t *tat; |
| 877 | if (!header) |
| 878 | return; |
| 879 | |
| 880 | printk(BIOS_DEBUG, "%s einj_smi = %p\n", __func__, einj_smi); |
| 881 | memset(einj_smi, 0, sizeof(acpi_einj_smi_t)); |
| 882 | tat = (acpi_einj_trigger_table_t *)(einj_smi + sizeof(acpi_einj_smi_t)); |
| 883 | tat->header_size = 16; |
| 884 | tat->revision = 0; |
| 885 | tat->table_size = sizeof(acpi_einj_trigger_table_t) + |
| 886 | sizeof(acpi_einj_action_table_t) * actions - 1; |
| 887 | tat->entry_count = actions; |
| 888 | printk(BIOS_DEBUG, "%s trigger_action_table = %p\n", __func__, tat); |
| 889 | |
| 890 | for (i = 0; i < actions; i++) { |
| 891 | tat->trigger_action[i].action = TRIGGER_ERROR; |
| 892 | tat->trigger_action[i].instruction = NO_OP; |
| 893 | tat->trigger_action[i].flags = FLAG_IGNORE; |
| 894 | tat->trigger_action[i].reg.space_id = ACPI_ADDRESS_SPACE_MEMORY; |
| 895 | tat->trigger_action[i].reg.bit_width = 64; |
| 896 | tat->trigger_action[i].reg.bit_offset = 0; |
| 897 | tat->trigger_action[i].reg.access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS; |
| 898 | tat->trigger_action[i].reg.addr = 0; |
| 899 | tat->trigger_action[i].value = 0; |
| 900 | tat->trigger_action[i].mask = 0xFFFFFFFF; |
| 901 | } |
| 902 | |
| 903 | acpi_einj_action_table_t default_actions[ACTION_COUNT] = { |
| 904 | [0] = { |
| 905 | .action = BEGIN_INJECT_OP, |
| 906 | .instruction = WRITE_REGISTER_VALUE, |
| 907 | .flags = FLAG_PRESERVE, |
| 908 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_state), |
| 909 | .value = 0, |
| 910 | .mask = 0xFFFFFFFF |
| 911 | }, |
| 912 | [1] = { |
| 913 | .action = GET_TRIGGER_ACTION_TABLE, |
| 914 | .instruction = READ_REGISTER, |
| 915 | .flags = FLAG_IGNORE, |
| 916 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->trigger_action_table), |
| 917 | .value = 0, |
| 918 | .mask = 0xFFFFFFFFFFFFFFFF |
| 919 | }, |
| 920 | [2] = { |
| 921 | .action = SET_ERROR_TYPE, |
| 922 | .instruction = WRITE_REGISTER, |
| 923 | .flags = FLAG_PRESERVE, |
| 924 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->err_inject[0]), |
| 925 | .value = 0, |
| 926 | .mask = 0xFFFFFFFF |
| 927 | }, |
| 928 | [3] = { |
| 929 | .action = GET_ERROR_TYPE, |
| 930 | .instruction = READ_REGISTER, |
| 931 | .flags = FLAG_IGNORE, |
| 932 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->err_inj_cap), |
| 933 | .value = 0, |
| 934 | .mask = 0xFFFFFFFF |
| 935 | }, |
| 936 | [4] = { |
| 937 | .action = END_INJECT_OP, |
| 938 | .instruction = WRITE_REGISTER_VALUE, |
| 939 | .flags = FLAG_PRESERVE, |
| 940 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_state), |
| 941 | .value = 0, |
| 942 | .mask = 0xFFFFFFFF |
| 943 | |
| 944 | }, |
| 945 | [5] = { |
| 946 | .action = EXECUTE_INJECT_OP, |
| 947 | .instruction = WRITE_REGISTER_VALUE, |
| 948 | .flags = FLAG_PRESERVE, |
| 949 | .reg = EINJ_REG_IO(), |
| 950 | .value = 0x9a, |
| 951 | .mask = 0xFFFF, |
| 952 | }, |
| 953 | [6] = { |
| 954 | .action = CHECK_BUSY_STATUS, |
| 955 | .instruction = READ_REGISTER_VALUE, |
| 956 | .flags = FLAG_IGNORE, |
| 957 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_status), |
| 958 | .value = 1, |
| 959 | .mask = 1, |
| 960 | }, |
| 961 | [7] = { |
| 962 | .action = GET_CMD_STATUS, |
| 963 | .instruction = READ_REGISTER, |
| 964 | .flags = FLAG_PRESERVE, |
| 965 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->cmd_sts), |
| 966 | .value = 0, |
| 967 | .mask = 0x1fe, |
| 968 | }, |
| 969 | [8] = { |
| 970 | .action = SET_ERROR_TYPE_WITH_ADDRESS, |
| 971 | .instruction = WRITE_REGISTER, |
| 972 | .flags = FLAG_PRESERVE, |
| 973 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->setaddrtable), |
| 974 | .value = 1, |
| 975 | .mask = 0xffffffff |
| 976 | } |
| 977 | }; |
| 978 | |
| 979 | einj_smi->err_inj_cap = ACPI_EINJ_DEFAULT_CAP; |
| 980 | einj_smi->trigger_action_table = (u64) (uintptr_t)tat; |
| 981 | |
| 982 | for (i = 0; i < ACTION_COUNT; i++) |
| 983 | printk(BIOS_DEBUG, "default_actions[%d].reg.addr is %llx\n", i, |
| 984 | default_actions[i].reg.addr); |
| 985 | |
Rocky Phagura | b46a9e5 | 2021-05-21 13:34:03 -0700 | [diff] [blame] | 986 | memset((void *)einj, 0, sizeof(*einj)); |
Rocky Phagura | eff0713 | 2021-01-10 15:42:50 -0800 | [diff] [blame] | 987 | |
| 988 | /* Fill out header fields. */ |
| 989 | memcpy(header->signature, "EINJ", 4); |
| 990 | memcpy(header->oem_id, OEM_ID, 6); |
| 991 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 992 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 993 | |
| 994 | header->asl_compiler_revision = asl_revision; |
| 995 | header->length = sizeof(acpi_einj_t); |
| 996 | header->revision = 1; |
| 997 | inj_header->einj_header_size = sizeof(acpi_injection_header_t); |
| 998 | inj_header->entry_count = ACTION_COUNT; |
| 999 | |
| 1000 | printk(BIOS_DEBUG, "%s einj->action_table = %p\n", |
| 1001 | __func__, einj->action_table); |
| 1002 | memcpy((void *)einj->action_table, (void *)default_actions, sizeof(einj->action_table)); |
Rocky Phagura | b46a9e5 | 2021-05-21 13:34:03 -0700 | [diff] [blame] | 1003 | header->checksum = acpi_checksum((void *)einj, sizeof(*einj)); |
Rocky Phagura | eff0713 | 2021-01-10 15:42:50 -0800 | [diff] [blame] | 1004 | } |
| 1005 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 1006 | void acpi_create_vfct(const struct device *device, |
Himanshu Sahdev | 7f1da07 | 2019-10-21 15:27:19 +0530 | [diff] [blame] | 1007 | acpi_vfct_t *vfct, |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 1008 | unsigned long (*acpi_fill_vfct)(const struct device *device, |
Himanshu Sahdev | 7f1da07 | 2019-10-21 15:27:19 +0530 | [diff] [blame] | 1009 | acpi_vfct_t *vfct_struct, unsigned long current)) |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 1010 | { |
| 1011 | acpi_header_t *header = &(vfct->header); |
Himanshu Sahdev | 7f1da07 | 2019-10-21 15:27:19 +0530 | [diff] [blame] | 1012 | unsigned long current = (unsigned long)vfct + sizeof(acpi_vfct_t); |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 1013 | |
Himanshu Sahdev | 7f1da07 | 2019-10-21 15:27:19 +0530 | [diff] [blame] | 1014 | memset((void *)vfct, 0, sizeof(acpi_vfct_t)); |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 1015 | |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 1016 | if (!header) |
| 1017 | return; |
| 1018 | |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 1019 | /* Fill out header fields. */ |
| 1020 | memcpy(header->signature, "VFCT", 4); |
| 1021 | memcpy(header->oem_id, OEM_ID, 6); |
| 1022 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 1023 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 1024 | |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 1025 | header->asl_compiler_revision = asl_revision; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1026 | header->revision = get_acpi_table_revision(VFCT); |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 1027 | |
| 1028 | current = acpi_fill_vfct(device, vfct, current); |
| 1029 | |
Kyösti Mälkki | fb49379 | 2019-06-30 06:29:52 +0300 | [diff] [blame] | 1030 | /* If no BIOS image, return with header->length == 0. */ |
| 1031 | if (!vfct->VBIOSImageOffset) |
| 1032 | return; |
| 1033 | |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 1034 | /* (Re)calculate length and checksum. */ |
| 1035 | header->length = current - (unsigned long)vfct; |
| 1036 | header->checksum = acpi_checksum((void *)vfct, header->length); |
| 1037 | } |
| 1038 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 1039 | void acpi_create_ipmi(const struct device *device, |
Patrick Rudolph | 9d98e5a | 2019-06-14 19:00:04 +0200 | [diff] [blame] | 1040 | struct acpi_spmi *spmi, |
| 1041 | const u16 ipmi_revision, |
| 1042 | const acpi_addr_t *addr, |
| 1043 | const enum acpi_ipmi_interface_type type, |
| 1044 | const s8 gpe_interrupt, |
| 1045 | const u32 apic_interrupt, |
| 1046 | const u32 uid) |
| 1047 | { |
| 1048 | acpi_header_t *header = &(spmi->header); |
| 1049 | memset((void *)spmi, 0, sizeof(struct acpi_spmi)); |
| 1050 | |
| 1051 | /* Fill out header fields. */ |
| 1052 | memcpy(header->signature, "SPMI", 4); |
| 1053 | memcpy(header->oem_id, OEM_ID, 6); |
| 1054 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 1055 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 1056 | |
| 1057 | header->asl_compiler_revision = asl_revision; |
| 1058 | header->length = sizeof(struct acpi_spmi); |
| 1059 | header->revision = get_acpi_table_revision(SPMI); |
| 1060 | |
| 1061 | spmi->reserved = 1; |
| 1062 | |
| 1063 | if (device->path.type == DEVICE_PATH_PCI) { |
| 1064 | spmi->pci_device_flag = ACPI_IPMI_PCI_DEVICE_FLAG; |
| 1065 | spmi->pci_bus = device->bus->secondary; |
| 1066 | spmi->pci_device = device->path.pci.devfn >> 3; |
| 1067 | spmi->pci_function = device->path.pci.devfn & 0x7; |
| 1068 | } else if (type != IPMI_INTERFACE_SSIF) { |
| 1069 | memcpy(spmi->uid, &uid, sizeof(spmi->uid)); |
| 1070 | } |
| 1071 | |
| 1072 | spmi->base_address = *addr; |
| 1073 | spmi->specification_revision = ipmi_revision; |
| 1074 | |
| 1075 | spmi->interface_type = type; |
| 1076 | |
| 1077 | if (gpe_interrupt >= 0 && gpe_interrupt < 32) { |
| 1078 | spmi->gpe = gpe_interrupt; |
| 1079 | spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_SCI; |
| 1080 | } |
| 1081 | if (apic_interrupt > 0) { |
| 1082 | spmi->global_system_interrupt = apic_interrupt; |
| 1083 | spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_APIC; |
| 1084 | } |
| 1085 | |
| 1086 | /* Calculate checksum. */ |
| 1087 | header->checksum = acpi_checksum((void *)spmi, header->length); |
| 1088 | } |
| 1089 | |
Timothy Pearson | ff8ccf0 | 2015-08-11 17:48:32 -0500 | [diff] [blame] | 1090 | void acpi_create_ivrs(acpi_ivrs_t *ivrs, |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 1091 | unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct, |
| 1092 | unsigned long current)) |
Timothy Pearson | ff8ccf0 | 2015-08-11 17:48:32 -0500 | [diff] [blame] | 1093 | { |
| 1094 | acpi_header_t *header = &(ivrs->header); |
| 1095 | unsigned long current = (unsigned long)ivrs + sizeof(acpi_ivrs_t); |
| 1096 | |
| 1097 | memset((void *)ivrs, 0, sizeof(acpi_ivrs_t)); |
| 1098 | |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 1099 | if (!header) |
| 1100 | return; |
| 1101 | |
Timothy Pearson | ff8ccf0 | 2015-08-11 17:48:32 -0500 | [diff] [blame] | 1102 | /* Fill out header fields. */ |
| 1103 | memcpy(header->signature, "IVRS", 4); |
| 1104 | memcpy(header->oem_id, OEM_ID, 6); |
| 1105 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 1106 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 1107 | |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 1108 | header->asl_compiler_revision = asl_revision; |
Timothy Pearson | ff8ccf0 | 2015-08-11 17:48:32 -0500 | [diff] [blame] | 1109 | header->length = sizeof(acpi_ivrs_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1110 | header->revision = get_acpi_table_revision(IVRS); |
Timothy Pearson | ff8ccf0 | 2015-08-11 17:48:32 -0500 | [diff] [blame] | 1111 | |
| 1112 | current = acpi_fill_ivrs(ivrs, current); |
| 1113 | |
| 1114 | /* (Re)calculate length and checksum. */ |
| 1115 | header->length = current - (unsigned long)ivrs; |
| 1116 | header->checksum = acpi_checksum((void *)ivrs, header->length); |
| 1117 | } |
| 1118 | |
Jason Glenesk | 61624b2 | 2020-11-02 20:06:23 -0800 | [diff] [blame] | 1119 | void acpi_create_crat(struct acpi_crat_header *crat, |
| 1120 | unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct, |
| 1121 | unsigned long current)) |
| 1122 | { |
| 1123 | acpi_header_t *header = &(crat->header); |
| 1124 | unsigned long current = (unsigned long)crat + sizeof(struct acpi_crat_header); |
| 1125 | |
| 1126 | memset((void *)crat, 0, sizeof(struct acpi_crat_header)); |
| 1127 | |
| 1128 | if (!header) |
| 1129 | return; |
| 1130 | |
| 1131 | /* Fill out header fields. */ |
| 1132 | memcpy(header->signature, "CRAT", 4); |
| 1133 | memcpy(header->oem_id, OEM_ID, 6); |
| 1134 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 1135 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 1136 | |
| 1137 | header->asl_compiler_revision = asl_revision; |
| 1138 | header->length = sizeof(struct acpi_crat_header); |
| 1139 | header->revision = get_acpi_table_revision(CRAT); |
| 1140 | |
| 1141 | current = acpi_fill_crat(crat, current); |
| 1142 | |
| 1143 | /* (Re)calculate length and checksum. */ |
| 1144 | header->length = current - (unsigned long)crat; |
| 1145 | header->checksum = acpi_checksum((void *)crat, header->length); |
| 1146 | } |
| 1147 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 1148 | unsigned long acpi_write_hpet(const struct device *device, unsigned long current, |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 1149 | acpi_rsdp_t *rsdp) |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1150 | { |
| 1151 | acpi_hpet_t *hpet; |
| 1152 | |
| 1153 | /* |
| 1154 | * We explicitly add these tables later on: |
| 1155 | */ |
| 1156 | printk(BIOS_DEBUG, "ACPI: * HPET\n"); |
| 1157 | |
| 1158 | hpet = (acpi_hpet_t *) current; |
| 1159 | current += sizeof(acpi_hpet_t); |
Felix Held | c469712 | 2019-06-20 13:50:17 +0200 | [diff] [blame] | 1160 | current = ALIGN_UP(current, 16); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1161 | acpi_create_hpet(hpet); |
| 1162 | acpi_add_table(rsdp, hpet); |
| 1163 | |
| 1164 | return current; |
| 1165 | } |
| 1166 | |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 1167 | void acpi_create_dbg2(acpi_dbg2_header_t *dbg2, |
| 1168 | int port_type, int port_subtype, |
| 1169 | acpi_addr_t *address, uint32_t address_size, |
| 1170 | const char *device_path) |
| 1171 | { |
| 1172 | uintptr_t current; |
| 1173 | acpi_dbg2_device_t *device; |
| 1174 | uint32_t *dbg2_addr_size; |
| 1175 | acpi_header_t *header; |
| 1176 | size_t path_len; |
| 1177 | const char *path; |
| 1178 | char *namespace; |
| 1179 | |
| 1180 | /* Fill out header fields. */ |
| 1181 | current = (uintptr_t)dbg2; |
| 1182 | memset(dbg2, 0, sizeof(acpi_dbg2_header_t)); |
| 1183 | header = &(dbg2->header); |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 1184 | |
| 1185 | if (!header) |
| 1186 | return; |
| 1187 | |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1188 | header->revision = get_acpi_table_revision(DBG2); |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 1189 | memcpy(header->signature, "DBG2", 4); |
| 1190 | memcpy(header->oem_id, OEM_ID, 6); |
| 1191 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 1192 | memcpy(header->asl_compiler_id, ASLC, 4); |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 1193 | header->asl_compiler_revision = asl_revision; |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 1194 | |
| 1195 | /* One debug device defined */ |
| 1196 | dbg2->devices_offset = sizeof(acpi_dbg2_header_t); |
| 1197 | dbg2->devices_count = 1; |
| 1198 | current += sizeof(acpi_dbg2_header_t); |
| 1199 | |
| 1200 | /* Device comes after the header */ |
| 1201 | device = (acpi_dbg2_device_t *)current; |
| 1202 | memset(device, 0, sizeof(acpi_dbg2_device_t)); |
| 1203 | current += sizeof(acpi_dbg2_device_t); |
| 1204 | |
| 1205 | device->revision = 0; |
| 1206 | device->address_count = 1; |
| 1207 | device->port_type = port_type; |
| 1208 | device->port_subtype = port_subtype; |
| 1209 | |
| 1210 | /* Base Address comes after device structure */ |
| 1211 | memcpy((void *)current, address, sizeof(acpi_addr_t)); |
| 1212 | device->base_address_offset = current - (uintptr_t)device; |
| 1213 | current += sizeof(acpi_addr_t); |
| 1214 | |
| 1215 | /* Address Size comes after address structure */ |
| 1216 | dbg2_addr_size = (uint32_t *)current; |
| 1217 | device->address_size_offset = current - (uintptr_t)device; |
| 1218 | *dbg2_addr_size = address_size; |
| 1219 | current += sizeof(uint32_t); |
| 1220 | |
| 1221 | /* Namespace string comes last, use '.' if not provided */ |
| 1222 | path = device_path ? : "."; |
| 1223 | /* Namespace string length includes NULL terminator */ |
| 1224 | path_len = strlen(path) + 1; |
| 1225 | namespace = (char *)current; |
| 1226 | device->namespace_string_length = path_len; |
| 1227 | device->namespace_string_offset = current - (uintptr_t)device; |
| 1228 | strncpy(namespace, path, path_len); |
| 1229 | current += path_len; |
| 1230 | |
| 1231 | /* Update structure lengths and checksum */ |
| 1232 | device->length = current - (uintptr_t)device; |
| 1233 | header->length = current - (uintptr_t)dbg2; |
| 1234 | header->checksum = acpi_checksum((uint8_t *)dbg2, header->length); |
| 1235 | } |
| 1236 | |
| 1237 | 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] | 1238 | const struct device *dev, uint8_t access_size) |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 1239 | { |
| 1240 | acpi_dbg2_header_t *dbg2 = (acpi_dbg2_header_t *)current; |
| 1241 | struct resource *res; |
| 1242 | acpi_addr_t address; |
| 1243 | |
| 1244 | if (!dev) { |
Wim Vervoorn | 6cd5243 | 2020-02-03 14:41:46 +0100 | [diff] [blame] | 1245 | printk(BIOS_DEBUG, "%s: Device not found\n", __func__); |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 1246 | return current; |
| 1247 | } |
Mario Scheithauer | f1eb0ea | 2017-11-21 13:52:53 +0100 | [diff] [blame] | 1248 | if (!dev->enabled) { |
| 1249 | printk(BIOS_INFO, "%s: Device not enabled\n", __func__); |
| 1250 | return current; |
| 1251 | } |
Angel Pons | 32d09be | 2021-11-03 13:27:45 +0100 | [diff] [blame] | 1252 | res = probe_resource(dev, PCI_BASE_ADDRESS_0); |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 1253 | if (!res) { |
| 1254 | printk(BIOS_ERR, "%s: Unable to find resource for %s\n", |
| 1255 | __func__, dev_path(dev)); |
| 1256 | return current; |
| 1257 | } |
| 1258 | |
| 1259 | memset(&address, 0, sizeof(address)); |
| 1260 | if (res->flags & IORESOURCE_IO) |
| 1261 | address.space_id = ACPI_ADDRESS_SPACE_IO; |
| 1262 | else if (res->flags & IORESOURCE_MEM) |
| 1263 | address.space_id = ACPI_ADDRESS_SPACE_MEMORY; |
| 1264 | else { |
| 1265 | printk(BIOS_ERR, "%s: Unknown address space type\n", __func__); |
| 1266 | return current; |
| 1267 | } |
| 1268 | |
| 1269 | address.addrl = (uint32_t)res->base; |
| 1270 | address.addrh = (uint32_t)((res->base >> 32) & 0xffffffff); |
| 1271 | address.access_size = access_size; |
| 1272 | |
| 1273 | acpi_create_dbg2(dbg2, |
| 1274 | ACPI_DBG2_PORT_SERIAL, |
| 1275 | ACPI_DBG2_PORT_SERIAL_16550, |
| 1276 | &address, res->size, |
| 1277 | acpi_device_path(dev)); |
| 1278 | |
| 1279 | if (dbg2->header.length) { |
| 1280 | current += dbg2->header.length; |
| 1281 | current = acpi_align_current(current); |
| 1282 | acpi_add_table(rsdp, dbg2); |
| 1283 | } |
| 1284 | |
| 1285 | return current; |
| 1286 | } |
| 1287 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 1288 | void acpi_create_facs(acpi_facs_t *facs) |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 1289 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1290 | memset((void *)facs, 0, sizeof(acpi_facs_t)); |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 1291 | |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 1292 | memcpy(facs->signature, "FACS", 4); |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 1293 | facs->length = sizeof(acpi_facs_t); |
| 1294 | facs->hardware_signature = 0; |
| 1295 | facs->firmware_waking_vector = 0; |
| 1296 | facs->global_lock = 0; |
| 1297 | facs->flags = 0; |
| 1298 | facs->x_firmware_waking_vector_l = 0; |
| 1299 | facs->x_firmware_waking_vector_h = 0; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1300 | facs->version = get_acpi_table_revision(FACS); |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 1301 | } |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 1302 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1303 | 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] | 1304 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1305 | acpi_header_t *header = &(rsdt->header); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 1306 | |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 1307 | if (!header) |
| 1308 | return; |
| 1309 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1310 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 1311 | memcpy(header->signature, "RSDT", 4); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1312 | memcpy(header->oem_id, oem_id, 6); |
| 1313 | memcpy(header->oem_table_id, oem_table_id, 8); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 1314 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 1315 | |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 1316 | header->asl_compiler_revision = asl_revision; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 1317 | header->length = sizeof(acpi_rsdt_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1318 | header->revision = get_acpi_table_revision(RSDT); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 1319 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1320 | /* Entries are filled in later, we come with an empty set. */ |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 1321 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1322 | /* Fix checksum. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 1323 | header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1326 | 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] | 1327 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1328 | acpi_header_t *header = &(xsdt->header); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 1329 | |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 1330 | if (!header) |
| 1331 | return; |
| 1332 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1333 | /* Fill out header fields. */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 1334 | memcpy(header->signature, "XSDT", 4); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1335 | memcpy(header->oem_id, oem_id, 6); |
| 1336 | memcpy(header->oem_table_id, oem_table_id, 8); |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 1337 | memcpy(header->asl_compiler_id, ASLC, 4); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 1338 | |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 1339 | header->asl_compiler_revision = asl_revision; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 1340 | header->length = sizeof(acpi_xsdt_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1341 | header->revision = get_acpi_table_revision(XSDT); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 1342 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1343 | /* Entries are filled in later, we come with an empty set. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 1344 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1345 | /* Fix checksum. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 1346 | header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t)); |
| 1347 | } |
| 1348 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1349 | static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt, |
| 1350 | acpi_xsdt_t *xsdt, char *oem_id) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 1351 | { |
Stefan Reinauer | d18faac | 2009-11-05 18:06:43 +0000 | [diff] [blame] | 1352 | memset(rsdp, 0, sizeof(acpi_rsdp_t)); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1353 | |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 1354 | memcpy(rsdp->signature, RSDP_SIG, 8); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1355 | memcpy(rsdp->oem_id, oem_id, 6); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1356 | |
| 1357 | rsdp->length = sizeof(acpi_rsdp_t); |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 1358 | rsdp->rsdt_address = (uintptr_t)rsdt; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1359 | |
| 1360 | /* |
| 1361 | * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2. |
| 1362 | * |
| 1363 | * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2. |
| 1364 | * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR |
| 1365 | * revision 0). |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 1366 | */ |
| 1367 | if (xsdt == NULL) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1368 | rsdp->revision = 0; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 1369 | } else { |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 1370 | rsdp->xsdt_address = (u64)(uintptr_t)xsdt; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1371 | rsdp->revision = get_acpi_table_revision(RSDP); |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 1372 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1373 | |
| 1374 | /* Calculate checksums. */ |
| 1375 | rsdp->checksum = acpi_checksum((void *)rsdp, 20); |
| 1376 | rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 1377 | } |
| 1378 | |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 1379 | unsigned long acpi_create_hest_error_source(acpi_hest_t *hest, |
| 1380 | acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len) |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 1381 | { |
| 1382 | acpi_header_t *header = &(hest->header); |
| 1383 | acpi_hest_hen_t *hen; |
| 1384 | void *pos; |
| 1385 | u16 len; |
| 1386 | |
| 1387 | pos = esd; |
| 1388 | memset(pos, 0, sizeof(acpi_hest_esd_t)); |
| 1389 | len = 0; |
| 1390 | esd->type = type; /* MCE */ |
| 1391 | esd->source_id = hest->error_source_count; |
| 1392 | esd->flags = 0; /* FIRMWARE_FIRST */ |
| 1393 | esd->enabled = 1; |
| 1394 | esd->prealloc_erecords = 1; |
| 1395 | esd->max_section_per_record = 0x1; |
| 1396 | |
| 1397 | len += sizeof(acpi_hest_esd_t); |
| 1398 | pos = esd + 1; |
| 1399 | |
| 1400 | switch (type) { |
| 1401 | case 0: /* MCE */ |
| 1402 | break; |
| 1403 | case 1: /* CMC */ |
| 1404 | hen = (acpi_hest_hen_t *) (pos); |
| 1405 | memset(pos, 0, sizeof(acpi_hest_hen_t)); |
| 1406 | hen->type = 3; /* SCI? */ |
| 1407 | hen->length = sizeof(acpi_hest_hen_t); |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 1408 | hen->conf_we = 0; /* Configuration Write Enable. */ |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 1409 | hen->poll_interval = 0; |
| 1410 | hen->vector = 0; |
| 1411 | hen->sw2poll_threshold_val = 0; |
| 1412 | hen->sw2poll_threshold_win = 0; |
| 1413 | hen->error_threshold_val = 0; |
| 1414 | hen->error_threshold_win = 0; |
| 1415 | len += sizeof(acpi_hest_hen_t); |
| 1416 | pos = hen + 1; |
| 1417 | break; |
| 1418 | case 2: /* NMI */ |
| 1419 | case 6: /* AER Root Port */ |
| 1420 | case 7: /* AER Endpoint */ |
| 1421 | case 8: /* AER Bridge */ |
| 1422 | case 9: /* Generic Hardware Error Source. */ |
| 1423 | /* TODO: */ |
| 1424 | break; |
| 1425 | default: |
| 1426 | printk(BIOS_DEBUG, "Invalid type of Error Source."); |
| 1427 | break; |
| 1428 | } |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 1429 | hest->error_source_count++; |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 1430 | |
| 1431 | memcpy(pos, data, data_len); |
| 1432 | len += data_len; |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 1433 | if (header) |
| 1434 | header->length += len; |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 1435 | |
| 1436 | return len; |
| 1437 | } |
| 1438 | |
| 1439 | /* ACPI 4.0 */ |
Vladimir Serbinenko | 807127f | 2014-11-09 13:36:18 +0100 | [diff] [blame] | 1440 | void acpi_write_hest(acpi_hest_t *hest, |
| 1441 | unsigned long (*acpi_fill_hest)(acpi_hest_t *hest)) |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 1442 | { |
| 1443 | acpi_header_t *header = &(hest->header); |
| 1444 | |
| 1445 | memset(hest, 0, sizeof(acpi_hest_t)); |
| 1446 | |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 1447 | if (!header) |
| 1448 | return; |
| 1449 | |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 1450 | memcpy(header->signature, "HEST", 4); |
| 1451 | memcpy(header->oem_id, OEM_ID, 6); |
| 1452 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 1453 | memcpy(header->asl_compiler_id, ASLC, 4); |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 1454 | header->asl_compiler_revision = asl_revision; |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 1455 | header->length += sizeof(acpi_hest_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1456 | header->revision = get_acpi_table_revision(HEST); |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 1457 | |
| 1458 | acpi_fill_hest(hest); |
| 1459 | |
| 1460 | /* Calculate checksums. */ |
| 1461 | header->checksum = acpi_checksum((void *)hest, header->length); |
| 1462 | } |
| 1463 | |
Marshall Dawson | 1d8d369 | 2018-09-04 13:45:26 -0600 | [diff] [blame] | 1464 | /* ACPI 3.0b */ |
| 1465 | void acpi_write_bert(acpi_bert_t *bert, uintptr_t region, size_t length) |
| 1466 | { |
| 1467 | acpi_header_t *header = &(bert->header); |
| 1468 | |
| 1469 | memset(bert, 0, sizeof(acpi_bert_t)); |
| 1470 | |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 1471 | if (!header) |
| 1472 | return; |
| 1473 | |
Marshall Dawson | 1d8d369 | 2018-09-04 13:45:26 -0600 | [diff] [blame] | 1474 | memcpy(header->signature, "BERT", 4); |
| 1475 | memcpy(header->oem_id, OEM_ID, 6); |
| 1476 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 1477 | memcpy(header->asl_compiler_id, ASLC, 4); |
Elyes HAOUAS | f8f2e8c | 2019-02-25 15:42:07 +0100 | [diff] [blame] | 1478 | header->asl_compiler_revision = asl_revision; |
Marshall Dawson | 1d8d369 | 2018-09-04 13:45:26 -0600 | [diff] [blame] | 1479 | header->length += sizeof(acpi_bert_t); |
| 1480 | header->revision = get_acpi_table_revision(BERT); |
| 1481 | |
| 1482 | bert->error_region = region; |
| 1483 | bert->region_length = length; |
| 1484 | |
| 1485 | /* Calculate checksums. */ |
| 1486 | header->checksum = acpi_checksum((void *)bert, header->length); |
| 1487 | } |
| 1488 | |
Angel Pons | 79572e4 | 2020-07-13 00:17:43 +0200 | [diff] [blame] | 1489 | __weak void arch_fill_fadt(acpi_fadt_t *fadt) { } |
Kyösti Mälkki | f9aac92 | 2020-05-30 16:16:28 +0300 | [diff] [blame] | 1490 | __weak void soc_fill_fadt(acpi_fadt_t *fadt) { } |
Kyösti Mälkki | 02fd15d | 2020-06-02 03:34:43 +0300 | [diff] [blame] | 1491 | __weak void mainboard_fill_fadt(acpi_fadt_t *fadt) { } |
Kyösti Mälkki | f9aac92 | 2020-05-30 16:16:28 +0300 | [diff] [blame] | 1492 | |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 1493 | 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] | 1494 | { |
| 1495 | acpi_header_t *header = &(fadt->header); |
| 1496 | |
| 1497 | memset((void *) fadt, 0, sizeof(acpi_fadt_t)); |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 1498 | |
| 1499 | if (!header) |
| 1500 | return; |
| 1501 | |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1502 | memcpy(header->signature, "FACP", 4); |
| 1503 | header->length = sizeof(acpi_fadt_t); |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1504 | header->revision = get_acpi_table_revision(FADT); |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1505 | memcpy(header->oem_id, OEM_ID, 6); |
| 1506 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 1507 | memcpy(header->asl_compiler_id, ASLC, 4); |
Elyes HAOUAS | 26071aa | 2019-02-15 08:21:33 +0100 | [diff] [blame] | 1508 | header->asl_compiler_revision = asl_revision; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1509 | |
| 1510 | fadt->firmware_ctrl = (unsigned long) facs; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1511 | fadt->x_firmware_ctl_l = (unsigned long)facs; |
| 1512 | fadt->x_firmware_ctl_h = 0; |
Kyösti Mälkki | d4acee8 | 2020-06-03 07:20:55 +0300 | [diff] [blame] | 1513 | |
| 1514 | fadt->dsdt = (unsigned long) dsdt; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1515 | fadt->x_dsdt_l = (unsigned long)dsdt; |
| 1516 | fadt->x_dsdt_h = 0; |
| 1517 | |
Kyösti Mälkki | d4acee8 | 2020-06-03 07:20:55 +0300 | [diff] [blame] | 1518 | /* should be 0 ACPI 3.0 */ |
| 1519 | fadt->reserved = 0; |
| 1520 | |
Kyösti Mälkki | e0d3868 | 2020-06-07 12:01:58 +0300 | [diff] [blame] | 1521 | fadt->preferred_pm_profile = acpi_get_preferred_pm_profile(); |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1522 | |
Nico Huber | d581137 | 2021-07-12 18:11:58 +0200 | [diff] [blame] | 1523 | if (CONFIG(USE_PC_CMOS_ALTCENTURY)) |
| 1524 | fadt->century = RTC_CLK_ALTCENTURY; |
| 1525 | |
Angel Pons | 79572e4 | 2020-07-13 00:17:43 +0200 | [diff] [blame] | 1526 | arch_fill_fadt(fadt); |
| 1527 | |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 1528 | acpi_fill_fadt(fadt); |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1529 | |
Kyösti Mälkki | f9aac92 | 2020-05-30 16:16:28 +0300 | [diff] [blame] | 1530 | soc_fill_fadt(fadt); |
Kyösti Mälkki | 02fd15d | 2020-06-02 03:34:43 +0300 | [diff] [blame] | 1531 | mainboard_fill_fadt(fadt); |
Kyösti Mälkki | f9aac92 | 2020-05-30 16:16:28 +0300 | [diff] [blame] | 1532 | |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1533 | header->checksum = |
| 1534 | acpi_checksum((void *) fadt, header->length); |
| 1535 | } |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1536 | |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1537 | void acpi_create_lpit(acpi_lpit_t *lpit) |
| 1538 | { |
| 1539 | acpi_header_t *header = &(lpit->header); |
| 1540 | unsigned long current = (unsigned long)lpit + sizeof(acpi_lpit_t); |
| 1541 | |
| 1542 | memset((void *)lpit, 0, sizeof(acpi_lpit_t)); |
| 1543 | |
| 1544 | if (!header) |
| 1545 | return; |
| 1546 | |
| 1547 | /* Fill out header fields. */ |
| 1548 | memcpy(header->signature, "LPIT", 4); |
| 1549 | memcpy(header->oem_id, OEM_ID, 6); |
| 1550 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 1551 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 1552 | |
| 1553 | header->asl_compiler_revision = asl_revision; |
| 1554 | header->revision = get_acpi_table_revision(LPIT); |
| 1555 | header->oem_revision = 42; |
| 1556 | header->length = sizeof(acpi_lpit_t); |
| 1557 | |
| 1558 | current = acpi_fill_lpit(current); |
| 1559 | |
| 1560 | /* (Re)calculate length and checksum. */ |
| 1561 | header->length = current - (unsigned long)lpit; |
| 1562 | header->checksum = acpi_checksum((void *)lpit, header->length); |
| 1563 | } |
| 1564 | |
| 1565 | unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid) |
| 1566 | { |
| 1567 | memset(lpi_desc, 0, sizeof(acpi_lpi_desc_ncst_t)); |
| 1568 | lpi_desc->header.length = sizeof(acpi_lpi_desc_ncst_t); |
| 1569 | lpi_desc->header.type = ACPI_LPI_DESC_TYPE_NATIVE_CSTATE; |
| 1570 | lpi_desc->header.uid = uid; |
| 1571 | |
| 1572 | return lpi_desc->header.length; |
| 1573 | } |
| 1574 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 1575 | unsigned long __weak fw_cfg_acpi_tables(unsigned long start) |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 1576 | { |
| 1577 | return 0; |
| 1578 | } |
| 1579 | |
Raul E Rangel | 6b446b9 | 2021-11-19 11:38:35 -0700 | [diff] [blame] | 1580 | void preload_acpi_dsdt(void) |
| 1581 | { |
| 1582 | const char *file = CONFIG_CBFS_PREFIX "/dsdt.aml"; |
| 1583 | |
| 1584 | if (!CONFIG(CBFS_PRELOAD)) |
| 1585 | return; |
| 1586 | |
| 1587 | printk(BIOS_DEBUG, "Preloading %s\n", file); |
| 1588 | cbfs_preload(file); |
| 1589 | } |
| 1590 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1591 | unsigned long write_acpi_tables(unsigned long start) |
| 1592 | { |
| 1593 | unsigned long current; |
| 1594 | acpi_rsdp_t *rsdp; |
| 1595 | acpi_rsdt_t *rsdt; |
| 1596 | acpi_xsdt_t *xsdt; |
| 1597 | acpi_fadt_t *fadt; |
| 1598 | acpi_facs_t *facs; |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1599 | acpi_header_t *slic_file, *slic; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1600 | acpi_header_t *ssdt; |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1601 | acpi_header_t *dsdt_file, *dsdt; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1602 | acpi_mcfg_t *mcfg; |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 1603 | acpi_tcpa_t *tcpa; |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 1604 | acpi_tpm2_t *tpm2; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1605 | acpi_madt_t *madt; |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1606 | acpi_lpit_t *lpit; |
Francois Toguo | 522e0db | 2021-01-21 09:55:19 -0800 | [diff] [blame] | 1607 | acpi_bert_t *bert; |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 1608 | struct device *dev; |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 1609 | unsigned long fw; |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1610 | size_t slic_size, dsdt_size; |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1611 | char oem_id[6], oem_table_id[8]; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1612 | |
| 1613 | current = start; |
| 1614 | |
| 1615 | /* Align ACPI tables to 16byte */ |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1616 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1617 | |
Patrick Rudolph | cfe08ff | 2019-09-10 15:40:47 +0200 | [diff] [blame] | 1618 | /* Special case for qemu */ |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 1619 | fw = fw_cfg_acpi_tables(current); |
Patrick Rudolph | cfe08ff | 2019-09-10 15:40:47 +0200 | [diff] [blame] | 1620 | if (fw) { |
| 1621 | rsdp = NULL; |
| 1622 | /* Find RSDP. */ |
| 1623 | for (void *p = (void *)current; p < (void *)fw; p += 16) { |
| 1624 | if (valid_rsdp((acpi_rsdp_t *)p)) { |
| 1625 | rsdp = p; |
| 1626 | break; |
| 1627 | } |
| 1628 | } |
| 1629 | if (!rsdp) |
| 1630 | return fw; |
| 1631 | |
| 1632 | /* Add BOOT0000 for Linux google firmware driver */ |
| 1633 | printk(BIOS_DEBUG, "ACPI: * SSDT\n"); |
| 1634 | ssdt = (acpi_header_t *)fw; |
| 1635 | current = (unsigned long)ssdt + sizeof(acpi_header_t); |
| 1636 | |
| 1637 | memset((void *)ssdt, 0, sizeof(acpi_header_t)); |
| 1638 | |
| 1639 | memcpy(&ssdt->signature, "SSDT", 4); |
| 1640 | ssdt->revision = get_acpi_table_revision(SSDT); |
| 1641 | memcpy(&ssdt->oem_id, OEM_ID, 6); |
| 1642 | memcpy(&ssdt->oem_table_id, oem_table_id, 8); |
| 1643 | ssdt->oem_revision = 42; |
| 1644 | memcpy(&ssdt->asl_compiler_id, ASLC, 4); |
| 1645 | ssdt->asl_compiler_revision = asl_revision; |
| 1646 | ssdt->length = sizeof(acpi_header_t); |
| 1647 | |
| 1648 | acpigen_set_current((char *) current); |
| 1649 | |
| 1650 | /* Write object to declare coreboot tables */ |
| 1651 | acpi_ssdt_write_cbtable(); |
| 1652 | |
| 1653 | /* (Re)calculate length and checksum. */ |
| 1654 | ssdt->length = current - (unsigned long)ssdt; |
| 1655 | ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length); |
| 1656 | |
| 1657 | acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR); |
| 1658 | |
| 1659 | acpi_add_table(rsdp, ssdt); |
| 1660 | |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 1661 | return fw; |
Patrick Rudolph | cfe08ff | 2019-09-10 15:40:47 +0200 | [diff] [blame] | 1662 | } |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 1663 | |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame] | 1664 | dsdt_file = cbfs_map(CONFIG_CBFS_PREFIX "/dsdt.aml", &dsdt_size); |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1665 | if (!dsdt_file) { |
| 1666 | printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n"); |
| 1667 | return current; |
| 1668 | } |
| 1669 | |
| 1670 | if (dsdt_file->length > dsdt_size |
Elyes HAOUAS | 7d87e76 | 2016-10-03 22:11:07 +0200 | [diff] [blame] | 1671 | || dsdt_file->length < sizeof(acpi_header_t) |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1672 | || memcmp(dsdt_file->signature, "DSDT", 4) != 0) { |
| 1673 | printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n"); |
| 1674 | return current; |
| 1675 | } |
| 1676 | |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame] | 1677 | slic_file = cbfs_map(CONFIG_CBFS_PREFIX "/slic", &slic_size); |
Vladimir Serbinenko | 2cb2978 | 2015-05-31 11:32:09 +0200 | [diff] [blame] | 1678 | if (slic_file |
| 1679 | && (slic_file->length > slic_size |
Elyes HAOUAS | 7d87e76 | 2016-10-03 22:11:07 +0200 | [diff] [blame] | 1680 | || slic_file->length < sizeof(acpi_header_t) |
Benjamin Doron | 2b2dc0c | 2020-09-12 02:55:57 +0000 | [diff] [blame] | 1681 | || (memcmp(slic_file->signature, "SLIC", 4) != 0 |
| 1682 | && memcmp(slic_file->signature, "MSDM", 4) != 0))) { |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1683 | slic_file = 0; |
| 1684 | } |
| 1685 | |
| 1686 | if (slic_file) { |
| 1687 | memcpy(oem_id, slic_file->oem_id, 6); |
| 1688 | memcpy(oem_table_id, slic_file->oem_table_id, 8); |
| 1689 | } else { |
| 1690 | memcpy(oem_id, OEM_ID, 6); |
| 1691 | memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 1692 | } |
| 1693 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1694 | printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start); |
| 1695 | |
| 1696 | /* We need at least an RSDP and an RSDT Table */ |
| 1697 | rsdp = (acpi_rsdp_t *) current; |
| 1698 | current += sizeof(acpi_rsdp_t); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1699 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1700 | rsdt = (acpi_rsdt_t *) current; |
| 1701 | current += sizeof(acpi_rsdt_t); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1702 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1703 | xsdt = (acpi_xsdt_t *) current; |
| 1704 | current += sizeof(acpi_xsdt_t); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1705 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1706 | |
| 1707 | /* clear all table memory */ |
| 1708 | memset((void *) start, 0, current - start); |
| 1709 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1710 | acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id); |
| 1711 | acpi_write_rsdt(rsdt, oem_id, oem_table_id); |
| 1712 | acpi_write_xsdt(xsdt, oem_id, oem_table_id); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1713 | |
| 1714 | printk(BIOS_DEBUG, "ACPI: * FACS\n"); |
Felix Held | c469712 | 2019-06-20 13:50:17 +0200 | [diff] [blame] | 1715 | current = ALIGN_UP(current, 64); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1716 | facs = (acpi_facs_t *) current; |
| 1717 | current += sizeof(acpi_facs_t); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1718 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1719 | acpi_create_facs(facs); |
| 1720 | |
| 1721 | printk(BIOS_DEBUG, "ACPI: * DSDT\n"); |
| 1722 | dsdt = (acpi_header_t *) current; |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1723 | memcpy(dsdt, dsdt_file, sizeof(acpi_header_t)); |
Vladimir Serbinenko | 334fd8e | 2014-10-05 11:10:35 +0200 | [diff] [blame] | 1724 | if (dsdt->length >= sizeof(acpi_header_t)) { |
| 1725 | current += sizeof(acpi_header_t); |
| 1726 | |
| 1727 | acpigen_set_current((char *) current); |
Kyösti Mälkki | 2ab4a96 | 2020-06-30 11:41:47 +0300 | [diff] [blame] | 1728 | |
Kyösti Mälkki | 37eb24b | 2021-01-11 18:40:37 +0200 | [diff] [blame] | 1729 | if (CONFIG(ACPI_SOC_NVS)) |
| 1730 | acpi_fill_gnvs(); |
Kyösti Mälkki | 3dc1792 | 2021-03-16 19:01:48 +0200 | [diff] [blame] | 1731 | if (CONFIG(CHROMEOS_NVS)) |
| 1732 | acpi_fill_cnvs(); |
Kyösti Mälkki | 2ab4a96 | 2020-06-30 11:41:47 +0300 | [diff] [blame] | 1733 | |
Vladimir Serbinenko | 334fd8e | 2014-10-05 11:10:35 +0200 | [diff] [blame] | 1734 | for (dev = all_devices; dev; dev = dev->next) |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 1735 | if (dev->ops && dev->ops->acpi_inject_dsdt) |
| 1736 | dev->ops->acpi_inject_dsdt(dev); |
Vladimir Serbinenko | 334fd8e | 2014-10-05 11:10:35 +0200 | [diff] [blame] | 1737 | current = (unsigned long) acpigen_get_current(); |
| 1738 | memcpy((char *)current, |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1739 | (char *)dsdt_file + sizeof(acpi_header_t), |
Vladimir Serbinenko | 334fd8e | 2014-10-05 11:10:35 +0200 | [diff] [blame] | 1740 | dsdt->length - sizeof(acpi_header_t)); |
| 1741 | current += dsdt->length - sizeof(acpi_header_t); |
| 1742 | |
| 1743 | /* (Re)calculate length and checksum. */ |
| 1744 | dsdt->length = current - (unsigned long)dsdt; |
| 1745 | dsdt->checksum = 0; |
| 1746 | dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length); |
| 1747 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1748 | |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1749 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1750 | |
| 1751 | printk(BIOS_DEBUG, "ACPI: * FADT\n"); |
| 1752 | fadt = (acpi_fadt_t *) current; |
| 1753 | current += sizeof(acpi_fadt_t); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1754 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1755 | |
| 1756 | acpi_create_fadt(fadt, facs, dsdt); |
| 1757 | acpi_add_table(rsdp, fadt); |
| 1758 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1759 | if (slic_file) { |
| 1760 | printk(BIOS_DEBUG, "ACPI: * SLIC\n"); |
| 1761 | slic = (acpi_header_t *)current; |
| 1762 | memcpy(slic, slic_file, slic_file->length); |
| 1763 | current += slic_file->length; |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1764 | current = acpi_align_current(current); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1765 | acpi_add_table(rsdp, slic); |
| 1766 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1767 | |
| 1768 | printk(BIOS_DEBUG, "ACPI: * SSDT\n"); |
| 1769 | ssdt = (acpi_header_t *)current; |
| 1770 | acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR); |
Vladimir Serbinenko | 9310df8 | 2014-10-10 20:40:41 +0200 | [diff] [blame] | 1771 | if (ssdt->length > sizeof(acpi_header_t)) { |
| 1772 | current += ssdt->length; |
| 1773 | acpi_add_table(rsdp, ssdt); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1774 | current = acpi_align_current(current); |
Vladimir Serbinenko | 9310df8 | 2014-10-10 20:40:41 +0200 | [diff] [blame] | 1775 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1776 | |
| 1777 | printk(BIOS_DEBUG, "ACPI: * MCFG\n"); |
| 1778 | mcfg = (acpi_mcfg_t *) current; |
| 1779 | acpi_create_mcfg(mcfg); |
| 1780 | if (mcfg->header.length > sizeof(acpi_mcfg_t)) { |
| 1781 | current += mcfg->header.length; |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1782 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1783 | acpi_add_table(rsdp, mcfg); |
| 1784 | } |
| 1785 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 1786 | if (CONFIG(TPM1)) { |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 1787 | printk(BIOS_DEBUG, "ACPI: * TCPA\n"); |
| 1788 | tcpa = (acpi_tcpa_t *) current; |
| 1789 | acpi_create_tcpa(tcpa); |
| 1790 | if (tcpa->header.length >= sizeof(acpi_tcpa_t)) { |
| 1791 | current += tcpa->header.length; |
| 1792 | current = acpi_align_current(current); |
| 1793 | acpi_add_table(rsdp, tcpa); |
| 1794 | } |
| 1795 | } |
| 1796 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 1797 | if (CONFIG(TPM2)) { |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 1798 | printk(BIOS_DEBUG, "ACPI: * TPM2\n"); |
| 1799 | tpm2 = (acpi_tpm2_t *) current; |
| 1800 | acpi_create_tpm2(tpm2); |
| 1801 | if (tpm2->header.length >= sizeof(acpi_tpm2_t)) { |
| 1802 | current += tpm2->header.length; |
| 1803 | current = acpi_align_current(current); |
| 1804 | acpi_add_table(rsdp, tpm2); |
| 1805 | } |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 1806 | } |
| 1807 | |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1808 | if (CONFIG(ACPI_LPIT)) { |
| 1809 | printk(BIOS_DEBUG, "ACPI: * LPIT\n"); |
| 1810 | |
| 1811 | lpit = (acpi_lpit_t *)current; |
| 1812 | acpi_create_lpit(lpit); |
| 1813 | if (lpit->header.length >= sizeof(acpi_lpit_t)) { |
| 1814 | current += lpit->header.length; |
| 1815 | current = acpi_align_current(current); |
| 1816 | acpi_add_table(rsdp, lpit); |
| 1817 | } |
| 1818 | } |
| 1819 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1820 | printk(BIOS_DEBUG, "ACPI: * MADT\n"); |
| 1821 | |
| 1822 | madt = (acpi_madt_t *) current; |
| 1823 | acpi_create_madt(madt); |
| 1824 | if (madt->header.length > sizeof(acpi_madt_t)) { |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 1825 | current += madt->header.length; |
| 1826 | acpi_add_table(rsdp, madt); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1827 | } |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1828 | |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1829 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1830 | |
Felix Held | fba47926 | 2021-05-28 16:11:43 +0200 | [diff] [blame] | 1831 | if (CONFIG(ACPI_BERT)) { |
Francois Toguo | 522e0db | 2021-01-21 09:55:19 -0800 | [diff] [blame] | 1832 | void *region; |
| 1833 | size_t size; |
Francois Toguo | 522e0db | 2021-01-21 09:55:19 -0800 | [diff] [blame] | 1834 | bert = (acpi_bert_t *) current; |
Felix Held | fba47926 | 2021-05-28 16:11:43 +0200 | [diff] [blame] | 1835 | if (acpi_soc_get_bert_region(®ion, &size) == CB_SUCCESS) { |
| 1836 | printk(BIOS_DEBUG, "ACPI: * BERT\n"); |
| 1837 | acpi_write_bert(bert, (uintptr_t)region, size); |
| 1838 | if (bert->header.length >= sizeof(acpi_bert_t)) { |
| 1839 | current += bert->header.length; |
| 1840 | acpi_add_table(rsdp, bert); |
| 1841 | } |
| 1842 | current = acpi_align_current(current); |
Francois Toguo | 522e0db | 2021-01-21 09:55:19 -0800 | [diff] [blame] | 1843 | } |
Francois Toguo | 522e0db | 2021-01-21 09:55:19 -0800 | [diff] [blame] | 1844 | } |
| 1845 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1846 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 1847 | |
| 1848 | for (dev = all_devices; dev; dev = dev->next) { |
| 1849 | if (dev->ops && dev->ops->write_acpi_tables) { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 1850 | current = dev->ops->write_acpi_tables(dev, current, |
| 1851 | rsdp); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1852 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1853 | } |
| 1854 | } |
| 1855 | |
| 1856 | printk(BIOS_INFO, "ACPI: done.\n"); |
| 1857 | return current; |
| 1858 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1859 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1860 | static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp) |
| 1861 | { |
| 1862 | if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0) |
| 1863 | return NULL; |
| 1864 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1865 | printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1866 | |
| 1867 | if (acpi_checksum((void *)rsdp, 20) != 0) |
| 1868 | return NULL; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1869 | printk(BIOS_DEBUG, "Checksum 1 passed\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1870 | |
| 1871 | if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp, |
| 1872 | rsdp->length) != 0)) |
| 1873 | return NULL; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1874 | printk(BIOS_DEBUG, "Checksum 2 passed all OK\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1875 | |
| 1876 | return rsdp; |
| 1877 | } |
| 1878 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1879 | void *acpi_find_wakeup_vector(void) |
| 1880 | { |
| 1881 | char *p, *end; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1882 | acpi_rsdt_t *rsdt; |
| 1883 | acpi_facs_t *facs; |
Martin Roth | c5f4926 | 2012-12-14 19:17:55 -0700 | [diff] [blame] | 1884 | acpi_fadt_t *fadt = NULL; |
Kyösti Mälkki | 072d436b | 2016-06-17 08:44:40 +0300 | [diff] [blame] | 1885 | acpi_rsdp_t *rsdp = NULL; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1886 | void *wake_vec; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1887 | int i; |
| 1888 | |
Kyösti Mälkki | b8c7ea0 | 2020-11-17 16:41:38 +0200 | [diff] [blame] | 1889 | if (!acpi_is_wakeup_s3()) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1890 | return NULL; |
| 1891 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1892 | printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1893 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1894 | /* Find RSDP. */ |
| 1895 | for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) { |
Lee Leahy | 0b5678f | 2017-03-16 16:01:40 -0700 | [diff] [blame] | 1896 | rsdp = valid_rsdp((acpi_rsdp_t *)p); |
| 1897 | if (rsdp) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1898 | break; |
| 1899 | } |
| 1900 | |
Angel Pons | 98a68ad | 2018-11-04 12:25:25 +0100 | [diff] [blame] | 1901 | if (rsdp == NULL) { |
| 1902 | printk(BIOS_ALERT, |
| 1903 | "No RSDP found, wake up from S3 not possible.\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1904 | return NULL; |
Angel Pons | 98a68ad | 2018-11-04 12:25:25 +0100 | [diff] [blame] | 1905 | } |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1906 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1907 | printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp); |
Stefan Reinauer | 71a3018 | 2015-07-30 16:28:13 -0700 | [diff] [blame] | 1908 | rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 1909 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1910 | end = (char *)rsdt + rsdt->header.length; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1911 | 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] | 1912 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1913 | for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) { |
Stefan Reinauer | 71a3018 | 2015-07-30 16:28:13 -0700 | [diff] [blame] | 1914 | fadt = (acpi_fadt_t *)(uintptr_t)rsdt->entry[i]; |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 1915 | if (strncmp((char *)fadt, "FACP", 4) == 0) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1916 | break; |
| 1917 | fadt = NULL; |
| 1918 | } |
| 1919 | |
Angel Pons | 98a68ad | 2018-11-04 12:25:25 +0100 | [diff] [blame] | 1920 | if (fadt == NULL) { |
| 1921 | printk(BIOS_ALERT, |
| 1922 | "No FADT found, wake up from S3 not possible.\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1923 | return NULL; |
Angel Pons | 98a68ad | 2018-11-04 12:25:25 +0100 | [diff] [blame] | 1924 | } |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1925 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1926 | printk(BIOS_DEBUG, "FADT found at %p\n", fadt); |
Stefan Reinauer | 71a3018 | 2015-07-30 16:28:13 -0700 | [diff] [blame] | 1927 | facs = (acpi_facs_t *)(uintptr_t)fadt->firmware_ctrl; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1928 | |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 1929 | if (facs == NULL) { |
Angel Pons | 98a68ad | 2018-11-04 12:25:25 +0100 | [diff] [blame] | 1930 | printk(BIOS_ALERT, |
| 1931 | "No FACS found, wake up from S3 not possible.\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1932 | return NULL; |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 1933 | } |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1934 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1935 | printk(BIOS_DEBUG, "FACS found at %p\n", facs); |
Stefan Reinauer | 71a3018 | 2015-07-30 16:28:13 -0700 | [diff] [blame] | 1936 | wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1937 | printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1938 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1939 | return wake_vec; |
| 1940 | } |
| 1941 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 1942 | __weak int acpi_get_gpe(int gpe) |
Duncan Laurie | 1f6e681 | 2016-09-19 12:04:19 -0700 | [diff] [blame] | 1943 | { |
| 1944 | return -1; /* implemented by SOC */ |
| 1945 | } |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1946 | |
| 1947 | int get_acpi_table_revision(enum acpi_tables table) |
| 1948 | { |
| 1949 | switch (table) { |
| 1950 | case FADT: |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame] | 1951 | return ACPI_FADT_REV_ACPI_6_0; |
Elyes HAOUAS | f288b39 | 2018-11-11 15:22:30 +0100 | [diff] [blame] | 1952 | case MADT: /* ACPI 3.0: 2, ACPI 4.0/5.0: 3, ACPI 6.2b/6.3: 5 */ |
Patrick Rudolph | 56a3ef2 | 2020-03-24 17:29:49 +0100 | [diff] [blame] | 1953 | return 3; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1954 | case MCFG: |
| 1955 | return 1; |
| 1956 | case TCPA: |
| 1957 | return 2; |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 1958 | case TPM2: |
| 1959 | return 4; |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1960 | case SSDT: /* ACPI 3.0 up to 6.3: 2 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1961 | return 2; |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1962 | case SRAT: /* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 up to 6.3: 3 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1963 | return 1; /* TODO Should probably be upgraded to 2 */ |
Jonathan Zhang | 2a4e1f4 | 2021-04-01 11:43:37 -0700 | [diff] [blame] | 1964 | case HMAT: /* ACPI 6.4: 2 */ |
| 1965 | return 2; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1966 | case DMAR: |
| 1967 | return 1; |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1968 | case SLIT: /* ACPI 2.0 up to 6.3: 1 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1969 | return 1; |
Patrick Rudolph | 9d98e5a | 2019-06-14 19:00:04 +0200 | [diff] [blame] | 1970 | case SPMI: /* IMPI 2.0 */ |
| 1971 | return 5; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1972 | case HPET: /* Currently 1. Table added in ACPI 2.0. */ |
| 1973 | return 1; |
Elyes HAOUAS | f288b39 | 2018-11-11 15:22:30 +0100 | [diff] [blame] | 1974 | case VFCT: /* ACPI 2.0/3.0/4.0: 1 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1975 | return 1; |
| 1976 | case IVRS: |
Jason Glenesk | 1916f89 | 2020-07-24 02:51:30 -0700 | [diff] [blame] | 1977 | return IVRS_FORMAT_MIXED; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1978 | case DBG2: |
| 1979 | return 0; |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1980 | case FACS: /* ACPI 2.0/3.0: 1, ACPI 4.0 up to 6.3: 2 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1981 | return 1; |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1982 | case RSDT: /* ACPI 1.0 up to 6.3: 1 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1983 | return 1; |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1984 | case XSDT: /* ACPI 2.0 up to 6.3: 1 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1985 | return 1; |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1986 | case RSDP: /* ACPI 2.0 up to 6.3: 2 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1987 | return 2; |
Rocky Phagura | eff0713 | 2021-01-10 15:42:50 -0800 | [diff] [blame] | 1988 | case EINJ: |
| 1989 | return 1; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1990 | case HEST: |
| 1991 | return 1; |
| 1992 | case NHLT: |
| 1993 | return 5; |
Marshall Dawson | 44705c6 | 2018-09-04 13:47:15 -0600 | [diff] [blame] | 1994 | case BERT: |
| 1995 | return 1; |
Jason Glenesk | 61624b2 | 2020-11-02 20:06:23 -0800 | [diff] [blame] | 1996 | case CRAT: |
| 1997 | return 1; |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1998 | case LPIT: /* ACPI 5.1 up to 6.3: 0 */ |
| 1999 | return 0; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 2000 | default: |
| 2001 | return -1; |
| 2002 | } |
| 2003 | return -1; |
| 2004 | } |