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