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