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