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