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