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