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