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> |
Jianjun Wang | 8565b94a | 2022-03-02 10:20:26 +0800 | [diff] [blame] | 19 | #include <cbfs.h> |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 20 | #include <cbmem.h> |
Elyes HAOUAS | e2d152c | 2019-06-21 07:06:50 +0200 | [diff] [blame] | 21 | #include <commonlib/helpers.h> |
Jianjun Wang | 8565b94a | 2022-03-02 10:20:26 +0800 | [diff] [blame] | 22 | #include <console/console.h> |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 23 | #include <cpu/cpu.h> |
Jianjun Wang | 8565b94a | 2022-03-02 10:20:26 +0800 | [diff] [blame] | 24 | #include <device/mmio.h> |
| 25 | #include <device/pci.h> |
Arthur Heymans | 736d4d2 | 2023-06-30 15:37:38 +0200 | [diff] [blame] | 26 | #include <drivers/uart/pl011.h> |
Jianjun Wang | 8565b94a | 2022-03-02 10:20:26 +0800 | [diff] [blame] | 27 | #include <string.h> |
Elyes HAOUAS | cdd2f63 | 2021-02-11 19:37:11 +0100 | [diff] [blame] | 28 | #include <types.h> |
Elyes HAOUAS | 26071aa | 2019-02-15 08:21:33 +0100 | [diff] [blame] | 29 | #include <version.h> |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 30 | |
Patrick Rudolph | cfe08ff | 2019-09-10 15:40:47 +0200 | [diff] [blame] | 31 | static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp); |
| 32 | |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 33 | u8 acpi_checksum(u8 *table, u32 length) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 34 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 35 | u8 ret = 0; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 36 | while (length--) { |
| 37 | ret += *table; |
| 38 | table++; |
| 39 | } |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 40 | return -ret; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 43 | /** |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 44 | * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length |
| 45 | * and checksum. |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 46 | */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 47 | void acpi_add_table(acpi_rsdp_t *rsdp, void *table) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 48 | { |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 49 | int i, entries_num; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 50 | acpi_rsdt_t *rsdt; |
| 51 | acpi_xsdt_t *xsdt = NULL; |
| 52 | |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 53 | /* The 32bit RSDT may not be valid if tables live above 4GiB */ |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 54 | rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address; |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 55 | xsdt = (acpi_xsdt_t *)(uintptr_t)rsdp->xsdt_address; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 56 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 57 | /* This should always be MAX_ACPI_TABLES. */ |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 58 | entries_num = ARRAY_SIZE(xsdt->entry); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 59 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 60 | for (i = 0; i < entries_num; i++) { |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 61 | if (xsdt->entry[i] == 0) |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 62 | break; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 65 | if (i >= entries_num) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 66 | 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] | 67 | "too many tables.\n"); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 68 | return; |
| 69 | } |
| 70 | |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 71 | /* Add table to the XSDT. */ |
| 72 | xsdt->entry[i] = (u64)(uintptr_t)table; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 73 | |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 74 | /* Fix XSDT length or the kernel will assume invalid entries. */ |
| 75 | xsdt->header.length = sizeof(acpi_header_t) + (sizeof(u64) * (i + 1)); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 76 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 77 | /* Re-calculate checksum. */ |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 78 | xsdt->header.checksum = 0; /* Hope this won't get optimized away */ |
| 79 | xsdt->header.checksum = acpi_checksum((u8 *)xsdt, xsdt->header.length); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 80 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 81 | /* |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 82 | * And now the same thing for the RSDT. We use the same index as for |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 83 | * now we want the XSDT and RSDT to always be in sync in coreboot. |
| 84 | */ |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 85 | if (rsdt && (uintptr_t)table < UINT32_MAX) { |
| 86 | /* Add table to the RSDT. */ |
| 87 | rsdt->entry[i] = (u32)(uintptr_t)table; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 88 | |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 89 | /* Fix RSDT length. */ |
| 90 | rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i + 1)); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 91 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 92 | /* Re-calculate checksum. */ |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 93 | rsdt->header.checksum = 0; |
| 94 | rsdt->header.checksum = acpi_checksum((u8 *)rsdt, rsdt->header.length); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 97 | printk(BIOS_DEBUG, "ACPI: added table %d/%d, length now %d\n", |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 98 | i + 1, entries_num, xsdt->header.length); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 101 | static enum cb_err acpi_fill_header(acpi_header_t *header, const char name[4], |
| 102 | enum acpi_tables table, uint32_t size) |
| 103 | { |
| 104 | if (!header) |
| 105 | return CB_ERR; |
| 106 | |
| 107 | /* Fill out header fields. */ |
| 108 | memcpy(header->signature, name, 4); |
| 109 | memcpy(header->oem_id, OEM_ID, 6); |
| 110 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 111 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 112 | |
| 113 | header->asl_compiler_revision = asl_revision; |
| 114 | header->revision = get_acpi_table_revision(table); |
| 115 | header->length = size; |
| 116 | |
| 117 | return CB_SUCCESS; |
| 118 | } |
| 119 | |
Arthur Heymans | 9362dd7 | 2023-06-08 19:56:51 +0200 | [diff] [blame] | 120 | static 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] | 121 | u16 seg_nr, u8 start, u8 end) |
Stefan Reinauer | 26d431a | 2009-01-20 19:17:51 +0000 | [diff] [blame] | 122 | { |
Vladimir Serbinenko | 60fccdc | 2014-10-05 11:05:16 +0200 | [diff] [blame] | 123 | memset(mmconfig, 0, sizeof(*mmconfig)); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 124 | mmconfig->base_address = base; |
| 125 | mmconfig->base_reserved = 0; |
| 126 | mmconfig->pci_segment_group_number = seg_nr; |
| 127 | mmconfig->start_bus_number = start; |
| 128 | mmconfig->end_bus_number = end; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 129 | |
| 130 | return sizeof(acpi_mcfg_mmconfig_t); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 133 | static void acpi_create_madt(acpi_header_t *header, void *unused) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 134 | { |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 135 | acpi_madt_t *madt = (acpi_madt_t *)header; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 136 | unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 137 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 138 | if (acpi_fill_header(header, "APIC", MADT, sizeof(acpi_madt_t)) != CB_SUCCESS) |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 139 | return; |
| 140 | |
Arthur Heymans | cd46e5f | 2023-06-22 21:34:16 +0200 | [diff] [blame] | 141 | current = acpi_arch_fill_madt(madt, current); |
Kyösti Mälkki | 10bdee1 | 2023-04-11 01:00:17 +0300 | [diff] [blame] | 142 | |
| 143 | if (CONFIG(ACPI_CUSTOM_MADT)) |
Kyösti Mälkki | a5fa534 | 2022-11-18 13:23:52 +0200 | [diff] [blame] | 144 | current = acpi_fill_madt(current); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 145 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 146 | /* (Re)calculate length . */ |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 147 | header->length = current - (unsigned long)madt; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Kyösti Mälkki | b54388d | 2021-02-14 15:09:45 +0200 | [diff] [blame] | 150 | static unsigned long acpi_fill_mcfg(unsigned long current) |
| 151 | { |
| 152 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current, |
Shelley Chen | 4e9bb33 | 2021-10-20 15:43:45 -0700 | [diff] [blame] | 153 | CONFIG_ECAM_MMCONF_BASE_ADDRESS, 0, 0, |
| 154 | CONFIG_ECAM_MMCONF_BUS_NUMBER - 1); |
Kyösti Mälkki | b54388d | 2021-02-14 15:09:45 +0200 | [diff] [blame] | 155 | return current; |
| 156 | } |
| 157 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 158 | /* MCFG is defined in the PCI Firmware Specification 3.0. */ |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 159 | static void acpi_create_mcfg(acpi_header_t *header, void *unused) |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 160 | { |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 161 | acpi_mcfg_t *mcfg = (acpi_mcfg_t *)header; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 162 | unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 163 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 164 | |
| 165 | if (acpi_fill_header(header, "MCFG", MCFG, sizeof(acpi_mcfg_t)) != CB_SUCCESS) |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 166 | return; |
| 167 | |
Shelley Chen | 4e9bb33 | 2021-10-20 15:43:45 -0700 | [diff] [blame] | 168 | if (CONFIG(ECAM_MMCONF_SUPPORT)) |
Kyösti Mälkki | b54388d | 2021-02-14 15:09:45 +0200 | [diff] [blame] | 169 | current = acpi_fill_mcfg(current); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 170 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 171 | /* (Re)calculate length */ |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 172 | header->length = current - (unsigned long)mcfg; |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 175 | static void *get_tcpa_log(u32 *size) |
| 176 | { |
| 177 | const struct cbmem_entry *ce; |
| 178 | const u32 tcpa_default_log_len = 0x10000; |
| 179 | void *lasa; |
Philipp Deppenwiese | 791ba97 | 2018-07-30 01:15:20 +0200 | [diff] [blame] | 180 | ce = cbmem_entry_find(CBMEM_ID_TCPA_TCG_LOG); |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 181 | if (ce) { |
| 182 | lasa = cbmem_entry_start(ce); |
| 183 | *size = cbmem_entry_size(ce); |
| 184 | printk(BIOS_DEBUG, "TCPA log found at %p\n", lasa); |
| 185 | return lasa; |
| 186 | } |
Philipp Deppenwiese | 791ba97 | 2018-07-30 01:15:20 +0200 | [diff] [blame] | 187 | lasa = cbmem_add(CBMEM_ID_TCPA_TCG_LOG, tcpa_default_log_len); |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 188 | if (!lasa) { |
| 189 | printk(BIOS_ERR, "TCPA log creation failed\n"); |
| 190 | return NULL; |
| 191 | } |
| 192 | |
| 193 | printk(BIOS_DEBUG, "TCPA log created at %p\n", lasa); |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 194 | memset(lasa, 0, tcpa_default_log_len); |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 195 | |
| 196 | *size = tcpa_default_log_len; |
| 197 | return lasa; |
| 198 | } |
| 199 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 200 | static void acpi_create_tcpa(acpi_header_t *header, void *unused) |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 201 | { |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 202 | if (!CONFIG(TPM1)) |
| 203 | return; |
| 204 | |
| 205 | acpi_tcpa_t *tcpa = (acpi_tcpa_t *)header; |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 206 | u32 tcpa_log_len; |
| 207 | void *lasa; |
| 208 | |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 209 | lasa = get_tcpa_log(&tcpa_log_len); |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 210 | if (!lasa) |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 211 | return; |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 212 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 213 | if (acpi_fill_header(header, "TCPA", TCPA, sizeof(acpi_tcpa_t)) != CB_SUCCESS) |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 214 | return; |
| 215 | |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 216 | tcpa->platform_class = 0; |
| 217 | tcpa->laml = tcpa_log_len; |
Elyes Haouas | 3141fbad | 2022-11-18 15:22:32 +0100 | [diff] [blame] | 218 | tcpa->lasa = (uintptr_t)lasa; |
Vladimir Serbinenko | f44ac13 | 2015-05-20 19:52:01 +0200 | [diff] [blame] | 219 | } |
| 220 | |
Michał Żygowski | 6e8692e | 2018-11-22 16:57:50 +0100 | [diff] [blame] | 221 | static void *get_tpm2_log(u32 *size) |
| 222 | { |
| 223 | const struct cbmem_entry *ce; |
| 224 | const u32 tpm2_default_log_len = 0x10000; |
| 225 | void *lasa; |
| 226 | ce = cbmem_entry_find(CBMEM_ID_TPM2_TCG_LOG); |
| 227 | if (ce) { |
| 228 | lasa = cbmem_entry_start(ce); |
| 229 | *size = cbmem_entry_size(ce); |
| 230 | printk(BIOS_DEBUG, "TPM2 log found at %p\n", lasa); |
| 231 | return lasa; |
| 232 | } |
| 233 | lasa = cbmem_add(CBMEM_ID_TPM2_TCG_LOG, tpm2_default_log_len); |
| 234 | if (!lasa) { |
| 235 | printk(BIOS_ERR, "TPM2 log creation failed\n"); |
| 236 | return NULL; |
| 237 | } |
| 238 | |
| 239 | printk(BIOS_DEBUG, "TPM2 log created at %p\n", lasa); |
| 240 | memset(lasa, 0, tpm2_default_log_len); |
| 241 | |
| 242 | *size = tpm2_default_log_len; |
| 243 | return lasa; |
| 244 | } |
| 245 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 246 | static void acpi_create_tpm2(acpi_header_t *header, void *unused) |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 247 | { |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 248 | if (!CONFIG(TPM2)) |
| 249 | return; |
| 250 | |
| 251 | acpi_tpm2_t *tpm2 = (acpi_tpm2_t *)header; |
Michał Żygowski | 6e8692e | 2018-11-22 16:57:50 +0100 | [diff] [blame] | 252 | u32 tpm2_log_len; |
| 253 | void *lasa; |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 254 | |
Michał Żygowski | 6e8692e | 2018-11-22 16:57:50 +0100 | [diff] [blame] | 255 | /* |
| 256 | * Some payloads like SeaBIOS depend on log area to use TPM2. |
| 257 | * Get the memory size and address of TPM2 log area or initialize it. |
| 258 | */ |
| 259 | lasa = get_tpm2_log(&tpm2_log_len); |
| 260 | if (!lasa) |
| 261 | tpm2_log_len = 0; |
| 262 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 263 | if (acpi_fill_header(header, "TPM2", TPM2, sizeof(acpi_tpm2_t)) != CB_SUCCESS) |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 264 | return; |
| 265 | |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 266 | /* Hard to detect for coreboot. Just set it to 0 */ |
| 267 | tpm2->platform_class = 0; |
Christian Walter | 26e0d4c | 2019-07-14 15:47:23 +0200 | [diff] [blame] | 268 | if (CONFIG(CRB_TPM)) { |
| 269 | /* Must be set to 7 for CRB Support */ |
| 270 | tpm2->control_area = CONFIG_CRB_TPM_BASE_ADDRESS + 0x40; |
| 271 | tpm2->start_method = 7; |
| 272 | } else { |
| 273 | /* Must be set to 0 for FIFO interface support */ |
| 274 | tpm2->control_area = 0; |
| 275 | tpm2->start_method = 6; |
| 276 | } |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 277 | memset(tpm2->msp, 0, sizeof(tpm2->msp)); |
| 278 | |
Michał Żygowski | 6e8692e | 2018-11-22 16:57:50 +0100 | [diff] [blame] | 279 | /* Fill the log area size and start address fields. */ |
| 280 | tpm2->laml = tpm2_log_len; |
Elyes Haouas | 3141fbad | 2022-11-18 15:22:32 +0100 | [diff] [blame] | 281 | tpm2->lasa = (uintptr_t)lasa; |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 282 | } |
| 283 | |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 284 | static void acpi_ssdt_write_cbtable(void) |
| 285 | { |
| 286 | const struct cbmem_entry *cbtable; |
| 287 | uintptr_t base; |
| 288 | uint32_t size; |
| 289 | |
| 290 | cbtable = cbmem_entry_find(CBMEM_ID_CBTABLE); |
| 291 | if (!cbtable) |
| 292 | return; |
| 293 | base = (uintptr_t)cbmem_entry_start(cbtable); |
| 294 | size = cbmem_entry_size(cbtable); |
| 295 | |
| 296 | acpigen_write_device("CTBL"); |
| 297 | acpigen_write_coreboot_hid(COREBOOT_ACPI_ID_CBTABLE); |
| 298 | acpigen_write_name_integer("_UID", 0); |
Matt DeVillier | ce10b6f | 2022-10-15 11:52:54 -0500 | [diff] [blame] | 299 | acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON); |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 300 | acpigen_write_name("_CRS"); |
| 301 | acpigen_write_resourcetemplate_header(); |
| 302 | acpigen_write_mem32fixed(0, base, size); |
| 303 | acpigen_write_resourcetemplate_footer(); |
| 304 | acpigen_pop_len(); |
| 305 | } |
| 306 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 307 | static void acpi_create_ssdt_generator(acpi_header_t *ssdt, void *unused) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 308 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 309 | unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t); |
| 310 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 311 | if (acpi_fill_header(ssdt, "SSDT", SSDT, sizeof(acpi_header_t)) != CB_SUCCESS) |
| 312 | return; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 313 | |
Elyes Haouas | 3141fbad | 2022-11-18 15:22:32 +0100 | [diff] [blame] | 314 | acpigen_set_current((char *)current); |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 315 | |
| 316 | /* Write object to declare coreboot tables */ |
| 317 | acpi_ssdt_write_cbtable(); |
| 318 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 319 | { |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 320 | struct device *dev; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 321 | for (dev = all_devices; dev; dev = dev->next) |
Karthikeyan Ramasubramanian | d1c0f95 | 2020-11-02 16:26:52 -0700 | [diff] [blame] | 322 | if (dev->enabled && dev->ops && dev->ops->acpi_fill_ssdt) |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 323 | dev->ops->acpi_fill_ssdt(dev); |
Elyes Haouas | 3141fbad | 2022-11-18 15:22:32 +0100 | [diff] [blame] | 324 | current = (unsigned long)acpigen_get_current(); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 325 | } |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 326 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 327 | /* (Re)calculate length and checksum. */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 328 | ssdt->length = current - (unsigned long)ssdt; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 331 | 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] | 332 | u32 flags) |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 333 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 334 | mem->type = 1; /* Memory affinity structure */ |
| 335 | mem->length = sizeof(acpi_srat_mem_t); |
| 336 | mem->base_address_low = (basek << 10); |
| 337 | mem->base_address_high = (basek >> (32 - 10)); |
| 338 | mem->length_low = (sizek << 10); |
| 339 | mem->length_high = (sizek >> (32 - 10)); |
| 340 | mem->proximity_domain = node; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 341 | mem->flags = flags; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 342 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 343 | return mem->length; |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Jonathan Zhang | 3164b64 | 2021-04-21 17:51:31 -0700 | [diff] [blame] | 346 | int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain, |
| 347 | u16 seg, u8 bus, u8 dev, u8 func, u32 flags) |
| 348 | { |
| 349 | gia->type = ACPI_SRAT_STRUCTURE_GIA; |
| 350 | gia->length = sizeof(acpi_srat_gia_t); |
| 351 | gia->proximity_domain = proximity_domain; |
| 352 | gia->dev_handle_type = ACPI_SRAT_GIA_DEV_HANDLE_PCI; |
| 353 | /* First two bytes has segment number */ |
| 354 | memcpy(gia->dev_handle, &seg, 2); |
| 355 | gia->dev_handle[2] = bus; /* Byte 2 has bus number */ |
| 356 | /* Byte 3 has bits 7:3 for dev, bits 2:0 for func */ |
| 357 | gia->dev_handle[3] = PCI_SLOT(dev) | PCI_FUNC(func); |
| 358 | gia->flags = flags; |
| 359 | |
| 360 | return gia->length; |
| 361 | } |
| 362 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 363 | /* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */ |
Vladimir Serbinenko | 5e59757 | 2014-10-11 23:45:40 +0200 | [diff] [blame] | 364 | void acpi_create_srat(acpi_srat_t *srat, |
| 365 | unsigned long (*acpi_fill_srat)(unsigned long current)) |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 366 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 367 | acpi_header_t *header = &(srat->header); |
| 368 | unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 369 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 370 | memset((void *)srat, 0, sizeof(acpi_srat_t)); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 371 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 372 | if (acpi_fill_header(header, "SRAT", SRAT, sizeof(acpi_srat_t)) != CB_SUCCESS) |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 373 | return; |
| 374 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 375 | srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */ |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 376 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 377 | current = acpi_fill_srat(current); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 378 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 379 | /* (Re)calculate length and checksum. */ |
| 380 | header->length = current - (unsigned long)srat; |
| 381 | header->checksum = acpi_checksum((void *)srat, header->length); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 382 | } |
| 383 | |
Jonathan Zhang | 3dcafa8 | 2022-05-11 13:11:20 -0700 | [diff] [blame] | 384 | int acpi_create_cedt_chbs(acpi_cedt_chbs_t *chbs, u32 uid, u32 cxl_ver, u64 base) |
| 385 | { |
| 386 | memset((void *)chbs, 0, sizeof(acpi_cedt_chbs_t)); |
| 387 | |
| 388 | chbs->type = ACPI_CEDT_STRUCTURE_CHBS; |
| 389 | chbs->length = sizeof(acpi_cedt_chbs_t); |
| 390 | chbs->uid = uid; |
| 391 | chbs->cxl_ver = cxl_ver; |
| 392 | chbs->base = base; |
| 393 | |
| 394 | /* |
| 395 | * CXL spec 2.0 section 9.14.1.2 "CXL CHBS" |
| 396 | * CXL 1.1 spec compliant host bridge: 8KB |
| 397 | * CXL 2.0 spec compliant host bridge: 64KB |
| 398 | */ |
| 399 | if (cxl_ver == ACPI_CEDT_CHBS_CXL_VER_1_1) |
| 400 | chbs->len = 8 * KiB; |
| 401 | else if (cxl_ver == ACPI_CEDT_CHBS_CXL_VER_2_0) |
| 402 | chbs->len = 64 * KiB; |
| 403 | else |
| 404 | printk(BIOS_ERR, "ACPI(%s:%s): Incorrect CXL version:%d\n", __FILE__, __func__, |
| 405 | cxl_ver); |
| 406 | |
| 407 | return chbs->length; |
| 408 | } |
| 409 | |
| 410 | int acpi_create_cedt_cfmws(acpi_cedt_cfmws_t *cfmws, u64 base_hpa, u64 window_size, u8 eniw, |
| 411 | u32 hbig, u16 restriction, u16 qtg_id, const u32 *interleave_target) |
| 412 | { |
| 413 | memset((void *)cfmws, 0, sizeof(acpi_cedt_cfmws_t)); |
| 414 | |
| 415 | cfmws->type = ACPI_CEDT_STRUCTURE_CFMWS; |
| 416 | |
| 417 | u8 niw = 0; |
| 418 | if (eniw >= 8) |
| 419 | printk(BIOS_ERR, "ACPI(%s:%s): Incorrect eniw::%d\n", __FILE__, __func__, eniw); |
| 420 | else |
| 421 | /* NIW = 2 ** ENIW */ |
| 422 | niw = 0x1 << eniw; |
| 423 | /* 36 + 4 * NIW */ |
| 424 | cfmws->length = sizeof(acpi_cedt_cfmws_t) + 4 * niw; |
| 425 | |
| 426 | cfmws->base_hpa = base_hpa; |
| 427 | cfmws->window_size = window_size; |
| 428 | cfmws->eniw = eniw; |
| 429 | |
| 430 | // 0: Standard Modulo Arithmetic. Other values reserved. |
| 431 | cfmws->interleave_arithmetic = 0; |
| 432 | |
| 433 | cfmws->hbig = hbig; |
| 434 | cfmws->restriction = restriction; |
| 435 | cfmws->qtg_id = qtg_id; |
| 436 | memcpy(&cfmws->interleave_target, interleave_target, 4 * niw); |
| 437 | |
| 438 | return cfmws->length; |
| 439 | } |
| 440 | |
| 441 | void acpi_create_cedt(acpi_cedt_t *cedt, unsigned long (*acpi_fill_cedt)(unsigned long current)) |
| 442 | { |
| 443 | acpi_header_t *header = &(cedt->header); |
| 444 | unsigned long current = (unsigned long)cedt + sizeof(acpi_cedt_t); |
| 445 | |
| 446 | memset((void *)cedt, 0, sizeof(acpi_cedt_t)); |
| 447 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 448 | if (acpi_fill_header(header, "CEDT", CEDT, sizeof(acpi_cedt_t)) != CB_SUCCESS) |
Jonathan Zhang | 3dcafa8 | 2022-05-11 13:11:20 -0700 | [diff] [blame] | 449 | return; |
| 450 | |
Jonathan Zhang | 3dcafa8 | 2022-05-11 13:11:20 -0700 | [diff] [blame] | 451 | current = acpi_fill_cedt(current); |
| 452 | |
| 453 | /* (Re)calculate length and checksum. */ |
| 454 | header->length = current - (unsigned long)cedt; |
| 455 | header->checksum = acpi_checksum((void *)cedt, header->length); |
| 456 | } |
| 457 | |
Jonathan Zhang | 2a4e1f4 | 2021-04-01 11:43:37 -0700 | [diff] [blame] | 458 | int acpi_create_hmat_mpda(acpi_hmat_mpda_t *mpda, u32 initiator, u32 memory) |
| 459 | { |
| 460 | memset((void *)mpda, 0, sizeof(acpi_hmat_mpda_t)); |
| 461 | |
| 462 | mpda->type = 0; /* Memory Proximity Domain Attributes structure */ |
| 463 | mpda->length = sizeof(acpi_hmat_mpda_t); |
| 464 | /* |
| 465 | * Proximity Domain for Attached Initiator field is valid. |
| 466 | * Bit 1 and bit 2 are reserved since HMAT revision 2. |
| 467 | */ |
| 468 | mpda->flags = (1 << 0); |
| 469 | mpda->proximity_domain_initiator = initiator; |
| 470 | mpda->proximity_domain_memory = memory; |
| 471 | |
| 472 | return mpda->length; |
| 473 | } |
| 474 | |
| 475 | void acpi_create_hmat(acpi_hmat_t *hmat, |
| 476 | unsigned long (*acpi_fill_hmat)(unsigned long current)) |
| 477 | { |
| 478 | acpi_header_t *header = &(hmat->header); |
| 479 | unsigned long current = (unsigned long)hmat + sizeof(acpi_hmat_t); |
| 480 | |
| 481 | memset((void *)hmat, 0, sizeof(acpi_hmat_t)); |
| 482 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 483 | if (acpi_fill_header(header, "HMAT", HMAT, sizeof(acpi_hmat_t)) != CB_SUCCESS) |
Jonathan Zhang | 2a4e1f4 | 2021-04-01 11:43:37 -0700 | [diff] [blame] | 484 | return; |
| 485 | |
Jonathan Zhang | 2a4e1f4 | 2021-04-01 11:43:37 -0700 | [diff] [blame] | 486 | current = acpi_fill_hmat(current); |
| 487 | |
| 488 | /* (Re)calculate length and checksum. */ |
| 489 | header->length = current - (unsigned long)hmat; |
| 490 | header->checksum = acpi_checksum((void *)hmat, header->length); |
| 491 | } |
| 492 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 493 | /* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */ |
Vladimir Serbinenko | 5e59757 | 2014-10-11 23:45:40 +0200 | [diff] [blame] | 494 | void acpi_create_slit(acpi_slit_t *slit, |
| 495 | unsigned long (*acpi_fill_slit)(unsigned long current)) |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 496 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 497 | acpi_header_t *header = &(slit->header); |
| 498 | unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 499 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 500 | memset((void *)slit, 0, sizeof(acpi_slit_t)); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 501 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 502 | if (acpi_fill_header(header, "SLIT", SLIT, sizeof(acpi_slit_t)) != CB_SUCCESS) |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 503 | return; |
| 504 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 505 | current = acpi_fill_slit(current); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 506 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 507 | /* (Re)calculate length and checksum. */ |
| 508 | header->length = current - (unsigned long)slit; |
| 509 | header->checksum = acpi_checksum((void *)slit, header->length); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Rocky Phagura | eff0713 | 2021-01-10 15:42:50 -0800 | [diff] [blame] | 512 | /* |
| 513 | * This method adds the ACPI error injection capability. It fills the default information. |
| 514 | * HW dependent code (caller) can modify the defaults upon return. If no changes are necessary |
| 515 | * and the defaults are acceptable then caller can simply add the table (acpi_add_table). |
| 516 | * INPUTS: |
| 517 | * einj - ptr to the starting location of EINJ table |
| 518 | * actions - number of actions to trigger an error (HW dependent) |
| 519 | * addr - address of trigger action table. This should be ACPI reserved memory and it will be |
| 520 | * shared between OS and FW. |
| 521 | */ |
| 522 | void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions) |
| 523 | { |
| 524 | int i; |
| 525 | acpi_header_t *header = &(einj->header); |
| 526 | acpi_injection_header_t *inj_header = &(einj->inj_header); |
| 527 | acpi_einj_smi_t *einj_smi = (acpi_einj_smi_t *)addr; |
| 528 | acpi_einj_trigger_table_t *tat; |
| 529 | if (!header) |
| 530 | return; |
| 531 | |
| 532 | printk(BIOS_DEBUG, "%s einj_smi = %p\n", __func__, einj_smi); |
| 533 | memset(einj_smi, 0, sizeof(acpi_einj_smi_t)); |
Jonathan Zhang | d5d9b28 | 2022-11-07 17:30:14 -0800 | [diff] [blame] | 534 | tat = (acpi_einj_trigger_table_t *)((uint8_t *)einj_smi + sizeof(acpi_einj_smi_t)); |
Rocky Phagura | eff0713 | 2021-01-10 15:42:50 -0800 | [diff] [blame] | 535 | tat->header_size = 16; |
| 536 | tat->revision = 0; |
| 537 | tat->table_size = sizeof(acpi_einj_trigger_table_t) + |
| 538 | sizeof(acpi_einj_action_table_t) * actions - 1; |
| 539 | tat->entry_count = actions; |
| 540 | printk(BIOS_DEBUG, "%s trigger_action_table = %p\n", __func__, tat); |
| 541 | |
| 542 | for (i = 0; i < actions; i++) { |
| 543 | tat->trigger_action[i].action = TRIGGER_ERROR; |
| 544 | tat->trigger_action[i].instruction = NO_OP; |
| 545 | tat->trigger_action[i].flags = FLAG_IGNORE; |
| 546 | tat->trigger_action[i].reg.space_id = ACPI_ADDRESS_SPACE_MEMORY; |
| 547 | tat->trigger_action[i].reg.bit_width = 64; |
| 548 | tat->trigger_action[i].reg.bit_offset = 0; |
| 549 | tat->trigger_action[i].reg.access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS; |
| 550 | tat->trigger_action[i].reg.addr = 0; |
| 551 | tat->trigger_action[i].value = 0; |
| 552 | tat->trigger_action[i].mask = 0xFFFFFFFF; |
| 553 | } |
| 554 | |
| 555 | acpi_einj_action_table_t default_actions[ACTION_COUNT] = { |
| 556 | [0] = { |
| 557 | .action = BEGIN_INJECT_OP, |
| 558 | .instruction = WRITE_REGISTER_VALUE, |
| 559 | .flags = FLAG_PRESERVE, |
| 560 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_state), |
| 561 | .value = 0, |
| 562 | .mask = 0xFFFFFFFF |
| 563 | }, |
| 564 | [1] = { |
| 565 | .action = GET_TRIGGER_ACTION_TABLE, |
| 566 | .instruction = READ_REGISTER, |
| 567 | .flags = FLAG_IGNORE, |
| 568 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->trigger_action_table), |
| 569 | .value = 0, |
| 570 | .mask = 0xFFFFFFFFFFFFFFFF |
| 571 | }, |
| 572 | [2] = { |
| 573 | .action = SET_ERROR_TYPE, |
| 574 | .instruction = WRITE_REGISTER, |
| 575 | .flags = FLAG_PRESERVE, |
| 576 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->err_inject[0]), |
| 577 | .value = 0, |
| 578 | .mask = 0xFFFFFFFF |
| 579 | }, |
| 580 | [3] = { |
| 581 | .action = GET_ERROR_TYPE, |
| 582 | .instruction = READ_REGISTER, |
| 583 | .flags = FLAG_IGNORE, |
| 584 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->err_inj_cap), |
| 585 | .value = 0, |
| 586 | .mask = 0xFFFFFFFF |
| 587 | }, |
| 588 | [4] = { |
| 589 | .action = END_INJECT_OP, |
| 590 | .instruction = WRITE_REGISTER_VALUE, |
| 591 | .flags = FLAG_PRESERVE, |
| 592 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_state), |
| 593 | .value = 0, |
| 594 | .mask = 0xFFFFFFFF |
| 595 | |
| 596 | }, |
| 597 | [5] = { |
| 598 | .action = EXECUTE_INJECT_OP, |
| 599 | .instruction = WRITE_REGISTER_VALUE, |
| 600 | .flags = FLAG_PRESERVE, |
| 601 | .reg = EINJ_REG_IO(), |
| 602 | .value = 0x9a, |
| 603 | .mask = 0xFFFF, |
| 604 | }, |
| 605 | [6] = { |
| 606 | .action = CHECK_BUSY_STATUS, |
| 607 | .instruction = READ_REGISTER_VALUE, |
| 608 | .flags = FLAG_IGNORE, |
| 609 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_status), |
| 610 | .value = 1, |
| 611 | .mask = 1, |
| 612 | }, |
| 613 | [7] = { |
| 614 | .action = GET_CMD_STATUS, |
| 615 | .instruction = READ_REGISTER, |
| 616 | .flags = FLAG_PRESERVE, |
| 617 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->cmd_sts), |
| 618 | .value = 0, |
| 619 | .mask = 0x1fe, |
| 620 | }, |
| 621 | [8] = { |
| 622 | .action = SET_ERROR_TYPE_WITH_ADDRESS, |
| 623 | .instruction = WRITE_REGISTER, |
| 624 | .flags = FLAG_PRESERVE, |
| 625 | .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->setaddrtable), |
| 626 | .value = 1, |
| 627 | .mask = 0xffffffff |
| 628 | } |
| 629 | }; |
| 630 | |
| 631 | einj_smi->err_inj_cap = ACPI_EINJ_DEFAULT_CAP; |
Elyes Haouas | 3141fbad | 2022-11-18 15:22:32 +0100 | [diff] [blame] | 632 | einj_smi->trigger_action_table = (u64)(uintptr_t)tat; |
Rocky Phagura | eff0713 | 2021-01-10 15:42:50 -0800 | [diff] [blame] | 633 | |
| 634 | for (i = 0; i < ACTION_COUNT; i++) |
| 635 | printk(BIOS_DEBUG, "default_actions[%d].reg.addr is %llx\n", i, |
| 636 | default_actions[i].reg.addr); |
| 637 | |
Rocky Phagura | b46a9e5 | 2021-05-21 13:34:03 -0700 | [diff] [blame] | 638 | memset((void *)einj, 0, sizeof(*einj)); |
Rocky Phagura | eff0713 | 2021-01-10 15:42:50 -0800 | [diff] [blame] | 639 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 640 | if (acpi_fill_header(header, "EINJ", EINJ, sizeof(acpi_einj_t)) != CB_SUCCESS) |
| 641 | return; |
Rocky Phagura | eff0713 | 2021-01-10 15:42:50 -0800 | [diff] [blame] | 642 | |
Rocky Phagura | eff0713 | 2021-01-10 15:42:50 -0800 | [diff] [blame] | 643 | inj_header->einj_header_size = sizeof(acpi_injection_header_t); |
| 644 | inj_header->entry_count = ACTION_COUNT; |
| 645 | |
| 646 | printk(BIOS_DEBUG, "%s einj->action_table = %p\n", |
| 647 | __func__, einj->action_table); |
| 648 | memcpy((void *)einj->action_table, (void *)default_actions, sizeof(einj->action_table)); |
Rocky Phagura | b46a9e5 | 2021-05-21 13:34:03 -0700 | [diff] [blame] | 649 | header->checksum = acpi_checksum((void *)einj, sizeof(*einj)); |
Rocky Phagura | eff0713 | 2021-01-10 15:42:50 -0800 | [diff] [blame] | 650 | } |
| 651 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 652 | void acpi_create_vfct(const struct device *device, |
Himanshu Sahdev | 7f1da07 | 2019-10-21 15:27:19 +0530 | [diff] [blame] | 653 | acpi_vfct_t *vfct, |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 654 | unsigned long (*acpi_fill_vfct)(const struct device *device, |
Himanshu Sahdev | 7f1da07 | 2019-10-21 15:27:19 +0530 | [diff] [blame] | 655 | acpi_vfct_t *vfct_struct, unsigned long current)) |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 656 | { |
| 657 | acpi_header_t *header = &(vfct->header); |
Himanshu Sahdev | 7f1da07 | 2019-10-21 15:27:19 +0530 | [diff] [blame] | 658 | unsigned long current = (unsigned long)vfct + sizeof(acpi_vfct_t); |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 659 | |
Himanshu Sahdev | 7f1da07 | 2019-10-21 15:27:19 +0530 | [diff] [blame] | 660 | memset((void *)vfct, 0, sizeof(acpi_vfct_t)); |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 661 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 662 | if (acpi_fill_header(header, "VFCT", VFCT, sizeof(acpi_vfct_t)) != CB_SUCCESS) |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 663 | return; |
| 664 | |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 665 | current = acpi_fill_vfct(device, vfct, current); |
| 666 | |
Kyösti Mälkki | fb49379 | 2019-06-30 06:29:52 +0300 | [diff] [blame] | 667 | /* If no BIOS image, return with header->length == 0. */ |
| 668 | if (!vfct->VBIOSImageOffset) |
| 669 | return; |
| 670 | |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 671 | /* (Re)calculate length and checksum. */ |
| 672 | header->length = current - (unsigned long)vfct; |
| 673 | header->checksum = acpi_checksum((void *)vfct, header->length); |
| 674 | } |
| 675 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 676 | void acpi_create_ipmi(const struct device *device, |
Patrick Rudolph | 9d98e5a | 2019-06-14 19:00:04 +0200 | [diff] [blame] | 677 | struct acpi_spmi *spmi, |
| 678 | const u16 ipmi_revision, |
| 679 | const acpi_addr_t *addr, |
| 680 | const enum acpi_ipmi_interface_type type, |
| 681 | const s8 gpe_interrupt, |
| 682 | const u32 apic_interrupt, |
| 683 | const u32 uid) |
| 684 | { |
| 685 | acpi_header_t *header = &(spmi->header); |
| 686 | memset((void *)spmi, 0, sizeof(struct acpi_spmi)); |
| 687 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 688 | if (acpi_fill_header(header, "SPMI", SPMI, sizeof(struct acpi_spmi)) != CB_SUCCESS) |
| 689 | return; |
Patrick Rudolph | 9d98e5a | 2019-06-14 19:00:04 +0200 | [diff] [blame] | 690 | |
| 691 | spmi->reserved = 1; |
| 692 | |
| 693 | if (device->path.type == DEVICE_PATH_PCI) { |
| 694 | spmi->pci_device_flag = ACPI_IPMI_PCI_DEVICE_FLAG; |
| 695 | spmi->pci_bus = device->bus->secondary; |
| 696 | spmi->pci_device = device->path.pci.devfn >> 3; |
| 697 | spmi->pci_function = device->path.pci.devfn & 0x7; |
| 698 | } else if (type != IPMI_INTERFACE_SSIF) { |
| 699 | memcpy(spmi->uid, &uid, sizeof(spmi->uid)); |
| 700 | } |
| 701 | |
| 702 | spmi->base_address = *addr; |
| 703 | spmi->specification_revision = ipmi_revision; |
| 704 | |
| 705 | spmi->interface_type = type; |
| 706 | |
| 707 | if (gpe_interrupt >= 0 && gpe_interrupt < 32) { |
| 708 | spmi->gpe = gpe_interrupt; |
| 709 | spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_SCI; |
| 710 | } |
| 711 | if (apic_interrupt > 0) { |
| 712 | spmi->global_system_interrupt = apic_interrupt; |
| 713 | spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_APIC; |
| 714 | } |
| 715 | |
| 716 | /* Calculate checksum. */ |
| 717 | header->checksum = acpi_checksum((void *)spmi, header->length); |
| 718 | } |
| 719 | |
Timothy Pearson | ff8ccf0 | 2015-08-11 17:48:32 -0500 | [diff] [blame] | 720 | void acpi_create_ivrs(acpi_ivrs_t *ivrs, |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 721 | unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct, |
| 722 | unsigned long current)) |
Timothy Pearson | ff8ccf0 | 2015-08-11 17:48:32 -0500 | [diff] [blame] | 723 | { |
| 724 | acpi_header_t *header = &(ivrs->header); |
| 725 | unsigned long current = (unsigned long)ivrs + sizeof(acpi_ivrs_t); |
| 726 | |
| 727 | memset((void *)ivrs, 0, sizeof(acpi_ivrs_t)); |
| 728 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 729 | if (acpi_fill_header(header, "IVRS", IVRS, sizeof(acpi_ivrs_t)) != CB_SUCCESS) |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 730 | return; |
| 731 | |
Timothy Pearson | ff8ccf0 | 2015-08-11 17:48:32 -0500 | [diff] [blame] | 732 | current = acpi_fill_ivrs(ivrs, current); |
| 733 | |
| 734 | /* (Re)calculate length and checksum. */ |
| 735 | header->length = current - (unsigned long)ivrs; |
| 736 | header->checksum = acpi_checksum((void *)ivrs, header->length); |
| 737 | } |
| 738 | |
Jason Glenesk | 61624b2 | 2020-11-02 20:06:23 -0800 | [diff] [blame] | 739 | void acpi_create_crat(struct acpi_crat_header *crat, |
| 740 | unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct, |
| 741 | unsigned long current)) |
| 742 | { |
| 743 | acpi_header_t *header = &(crat->header); |
| 744 | unsigned long current = (unsigned long)crat + sizeof(struct acpi_crat_header); |
| 745 | |
| 746 | memset((void *)crat, 0, sizeof(struct acpi_crat_header)); |
| 747 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 748 | if (acpi_fill_header(header, "CRAT", CRAT, sizeof(struct acpi_crat_header)) != CB_SUCCESS) |
Jason Glenesk | 61624b2 | 2020-11-02 20:06:23 -0800 | [diff] [blame] | 749 | return; |
| 750 | |
Jason Glenesk | 61624b2 | 2020-11-02 20:06:23 -0800 | [diff] [blame] | 751 | current = acpi_fill_crat(crat, current); |
| 752 | |
| 753 | /* (Re)calculate length and checksum. */ |
| 754 | header->length = current - (unsigned long)crat; |
| 755 | header->checksum = acpi_checksum((void *)crat, header->length); |
| 756 | } |
| 757 | |
Arthur Heymans | 9368cf9 | 2023-04-25 16:07:49 +0200 | [diff] [blame] | 758 | static void acpi_create_dbg2(acpi_dbg2_header_t *dbg2, |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 759 | int port_type, int port_subtype, |
| 760 | acpi_addr_t *address, uint32_t address_size, |
| 761 | const char *device_path) |
| 762 | { |
| 763 | uintptr_t current; |
| 764 | acpi_dbg2_device_t *device; |
| 765 | uint32_t *dbg2_addr_size; |
| 766 | acpi_header_t *header; |
| 767 | size_t path_len; |
| 768 | const char *path; |
| 769 | char *namespace; |
| 770 | |
| 771 | /* Fill out header fields. */ |
| 772 | current = (uintptr_t)dbg2; |
| 773 | memset(dbg2, 0, sizeof(acpi_dbg2_header_t)); |
| 774 | header = &(dbg2->header); |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 775 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 776 | if (acpi_fill_header(header, "DBG2", DBG2, sizeof(acpi_dbg2_header_t)) != CB_SUCCESS) |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 777 | return; |
| 778 | |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 779 | /* One debug device defined */ |
| 780 | dbg2->devices_offset = sizeof(acpi_dbg2_header_t); |
| 781 | dbg2->devices_count = 1; |
| 782 | current += sizeof(acpi_dbg2_header_t); |
| 783 | |
| 784 | /* Device comes after the header */ |
| 785 | device = (acpi_dbg2_device_t *)current; |
| 786 | memset(device, 0, sizeof(acpi_dbg2_device_t)); |
| 787 | current += sizeof(acpi_dbg2_device_t); |
| 788 | |
| 789 | device->revision = 0; |
| 790 | device->address_count = 1; |
| 791 | device->port_type = port_type; |
| 792 | device->port_subtype = port_subtype; |
| 793 | |
| 794 | /* Base Address comes after device structure */ |
| 795 | memcpy((void *)current, address, sizeof(acpi_addr_t)); |
| 796 | device->base_address_offset = current - (uintptr_t)device; |
| 797 | current += sizeof(acpi_addr_t); |
| 798 | |
| 799 | /* Address Size comes after address structure */ |
| 800 | dbg2_addr_size = (uint32_t *)current; |
| 801 | device->address_size_offset = current - (uintptr_t)device; |
| 802 | *dbg2_addr_size = address_size; |
| 803 | current += sizeof(uint32_t); |
| 804 | |
| 805 | /* Namespace string comes last, use '.' if not provided */ |
| 806 | path = device_path ? : "."; |
| 807 | /* Namespace string length includes NULL terminator */ |
| 808 | path_len = strlen(path) + 1; |
| 809 | namespace = (char *)current; |
| 810 | device->namespace_string_length = path_len; |
| 811 | device->namespace_string_offset = current - (uintptr_t)device; |
| 812 | strncpy(namespace, path, path_len); |
| 813 | current += path_len; |
| 814 | |
| 815 | /* Update structure lengths and checksum */ |
| 816 | device->length = current - (uintptr_t)device; |
| 817 | header->length = current - (uintptr_t)dbg2; |
| 818 | header->checksum = acpi_checksum((uint8_t *)dbg2, header->length); |
| 819 | } |
| 820 | |
Arthur Heymans | 736d4d2 | 2023-06-30 15:37:38 +0200 | [diff] [blame] | 821 | static unsigned long acpi_write_dbg2_uart(acpi_rsdp_t *rsdp, unsigned long current, |
| 822 | int space_id, uint64_t base, uint32_t size, |
| 823 | int access_size, const char *name) |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 824 | { |
| 825 | acpi_dbg2_header_t *dbg2 = (acpi_dbg2_header_t *)current; |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 826 | acpi_addr_t address; |
| 827 | |
Arthur Heymans | 736d4d2 | 2023-06-30 15:37:38 +0200 | [diff] [blame] | 828 | memset(&address, 0, sizeof(address)); |
| 829 | |
| 830 | address.space_id = space_id; |
| 831 | address.addrl = (uint32_t)base; |
| 832 | address.addrh = (uint32_t)((base >> 32) & 0xffffffff); |
| 833 | address.access_size = access_size; |
| 834 | |
| 835 | int subtype; |
| 836 | /* 16550-compatible with parameters defined in Generic Address Structure */ |
| 837 | if (CONFIG(DRIVERS_UART_8250IO) || CONFIG(DRIVERS_UART_8250MEM)) |
| 838 | subtype = ACPI_DBG2_PORT_SERIAL_16550; |
| 839 | else if (CONFIG(DRIVERS_UART_PL011)) |
| 840 | subtype = ACPI_DBG2_PORT_SERIAL_ARM_PL011; |
| 841 | else |
| 842 | return current; |
| 843 | |
| 844 | acpi_create_dbg2(dbg2, |
| 845 | ACPI_DBG2_PORT_SERIAL, |
| 846 | subtype, |
| 847 | &address, size, |
| 848 | name); |
| 849 | |
| 850 | if (dbg2->header.length) { |
| 851 | current += dbg2->header.length; |
| 852 | current = acpi_align_current(current); |
| 853 | acpi_add_table(rsdp, dbg2); |
| 854 | } |
| 855 | |
| 856 | return current; |
| 857 | } |
| 858 | |
| 859 | unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current, |
| 860 | const struct device *dev, uint8_t access_size) |
| 861 | { |
| 862 | struct resource *res; |
| 863 | |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 864 | if (!dev) { |
Wim Vervoorn | 6cd5243 | 2020-02-03 14:41:46 +0100 | [diff] [blame] | 865 | printk(BIOS_DEBUG, "%s: Device not found\n", __func__); |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 866 | return current; |
| 867 | } |
Mario Scheithauer | f1eb0ea | 2017-11-21 13:52:53 +0100 | [diff] [blame] | 868 | if (!dev->enabled) { |
| 869 | printk(BIOS_INFO, "%s: Device not enabled\n", __func__); |
| 870 | return current; |
| 871 | } |
Angel Pons | 32d09be | 2021-11-03 13:27:45 +0100 | [diff] [blame] | 872 | res = probe_resource(dev, PCI_BASE_ADDRESS_0); |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 873 | if (!res) { |
| 874 | printk(BIOS_ERR, "%s: Unable to find resource for %s\n", |
| 875 | __func__, dev_path(dev)); |
| 876 | return current; |
| 877 | } |
| 878 | |
Arthur Heymans | 736d4d2 | 2023-06-30 15:37:38 +0200 | [diff] [blame] | 879 | int space_id; |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 880 | if (res->flags & IORESOURCE_IO) |
Arthur Heymans | 736d4d2 | 2023-06-30 15:37:38 +0200 | [diff] [blame] | 881 | space_id = ACPI_ADDRESS_SPACE_IO; |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 882 | else if (res->flags & IORESOURCE_MEM) |
Arthur Heymans | 736d4d2 | 2023-06-30 15:37:38 +0200 | [diff] [blame] | 883 | space_id = ACPI_ADDRESS_SPACE_MEMORY; |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 884 | else { |
| 885 | printk(BIOS_ERR, "%s: Unknown address space type\n", __func__); |
| 886 | return current; |
| 887 | } |
| 888 | |
Arthur Heymans | 736d4d2 | 2023-06-30 15:37:38 +0200 | [diff] [blame] | 889 | return acpi_write_dbg2_uart(rsdp, current, space_id, res->base, res->size, access_size, acpi_device_path(dev)); |
| 890 | } |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 891 | |
Arthur Heymans | 736d4d2 | 2023-06-30 15:37:38 +0200 | [diff] [blame] | 892 | unsigned long acpi_pl011_write_dbg2_uart(acpi_rsdp_t *rsdp, unsigned long current, |
| 893 | uint64_t base, const char *name) |
| 894 | { |
| 895 | return acpi_write_dbg2_uart(rsdp, current, ACPI_ADDRESS_SPACE_MEMORY, base, |
| 896 | sizeof(struct pl011_uart), ACPI_ACCESS_SIZE_DWORD_ACCESS, |
| 897 | name); |
Duncan Laurie | e4a36c7 | 2017-11-11 19:33:25 -0800 | [diff] [blame] | 898 | } |
| 899 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 900 | static void acpi_create_facs(void *header) |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 901 | { |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 902 | acpi_facs_t *facs = header; |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 903 | |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 904 | memcpy(facs->signature, "FACS", 4); |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 905 | facs->length = sizeof(acpi_facs_t); |
| 906 | facs->hardware_signature = 0; |
| 907 | facs->firmware_waking_vector = 0; |
| 908 | facs->global_lock = 0; |
| 909 | facs->flags = 0; |
| 910 | facs->x_firmware_waking_vector_l = 0; |
| 911 | facs->x_firmware_waking_vector_h = 0; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 912 | facs->version = get_acpi_table_revision(FACS); |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 913 | } |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 914 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 915 | 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] | 916 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 917 | acpi_header_t *header = &(rsdt->header); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 918 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 919 | if (acpi_fill_header(header, "RSDT", RSDT, sizeof(acpi_rsdt_t)) != CB_SUCCESS) |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 920 | return; |
| 921 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 922 | /* Entries are filled in later, we come with an empty set. */ |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 923 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 924 | /* Fix checksum. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 925 | header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 928 | 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] | 929 | { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 930 | acpi_header_t *header = &(xsdt->header); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 931 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 932 | if (acpi_fill_header(header, "XSDT", XSDT, sizeof(acpi_xsdt_t)) != CB_SUCCESS) |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 933 | return; |
| 934 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 935 | /* Entries are filled in later, we come with an empty set. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 936 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 937 | /* Fix checksum. */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 938 | header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t)); |
| 939 | } |
| 940 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 941 | static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt, |
| 942 | acpi_xsdt_t *xsdt, char *oem_id) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 943 | { |
Stefan Reinauer | d18faac | 2009-11-05 18:06:43 +0000 | [diff] [blame] | 944 | memset(rsdp, 0, sizeof(acpi_rsdp_t)); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 945 | |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 946 | memcpy(rsdp->signature, RSDP_SIG, 8); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 947 | memcpy(rsdp->oem_id, oem_id, 6); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 948 | |
| 949 | rsdp->length = sizeof(acpi_rsdp_t); |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 950 | rsdp->rsdt_address = (uintptr_t)rsdt; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 951 | |
| 952 | /* |
| 953 | * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2. |
| 954 | * |
| 955 | * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2. |
| 956 | * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR |
| 957 | * revision 0). |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 958 | */ |
| 959 | if (xsdt == NULL) { |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 960 | rsdp->revision = 0; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 961 | } else { |
Stefan Reinauer | defee17 | 2015-06-18 01:11:19 -0700 | [diff] [blame] | 962 | rsdp->xsdt_address = (u64)(uintptr_t)xsdt; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 963 | rsdp->revision = get_acpi_table_revision(RSDP); |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 964 | } |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 965 | |
| 966 | /* Calculate checksums. */ |
| 967 | rsdp->checksum = acpi_checksum((void *)rsdp, 20); |
| 968 | rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 971 | unsigned long acpi_create_hest_error_source(acpi_hest_t *hest, |
| 972 | acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len) |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 973 | { |
| 974 | acpi_header_t *header = &(hest->header); |
| 975 | acpi_hest_hen_t *hen; |
| 976 | void *pos; |
| 977 | u16 len; |
| 978 | |
| 979 | pos = esd; |
| 980 | memset(pos, 0, sizeof(acpi_hest_esd_t)); |
| 981 | len = 0; |
| 982 | esd->type = type; /* MCE */ |
| 983 | esd->source_id = hest->error_source_count; |
| 984 | esd->flags = 0; /* FIRMWARE_FIRST */ |
| 985 | esd->enabled = 1; |
| 986 | esd->prealloc_erecords = 1; |
| 987 | esd->max_section_per_record = 0x1; |
| 988 | |
| 989 | len += sizeof(acpi_hest_esd_t); |
| 990 | pos = esd + 1; |
| 991 | |
| 992 | switch (type) { |
| 993 | case 0: /* MCE */ |
| 994 | break; |
| 995 | case 1: /* CMC */ |
Elyes Haouas | 3141fbad | 2022-11-18 15:22:32 +0100 | [diff] [blame] | 996 | hen = (acpi_hest_hen_t *)(pos); |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 997 | memset(pos, 0, sizeof(acpi_hest_hen_t)); |
| 998 | hen->type = 3; /* SCI? */ |
| 999 | hen->length = sizeof(acpi_hest_hen_t); |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 1000 | hen->conf_we = 0; /* Configuration Write Enable. */ |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 1001 | hen->poll_interval = 0; |
| 1002 | hen->vector = 0; |
| 1003 | hen->sw2poll_threshold_val = 0; |
| 1004 | hen->sw2poll_threshold_win = 0; |
| 1005 | hen->error_threshold_val = 0; |
| 1006 | hen->error_threshold_win = 0; |
| 1007 | len += sizeof(acpi_hest_hen_t); |
| 1008 | pos = hen + 1; |
| 1009 | break; |
| 1010 | case 2: /* NMI */ |
| 1011 | case 6: /* AER Root Port */ |
| 1012 | case 7: /* AER Endpoint */ |
| 1013 | case 8: /* AER Bridge */ |
| 1014 | case 9: /* Generic Hardware Error Source. */ |
| 1015 | /* TODO: */ |
| 1016 | break; |
| 1017 | default: |
| 1018 | printk(BIOS_DEBUG, "Invalid type of Error Source."); |
| 1019 | break; |
| 1020 | } |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 1021 | hest->error_source_count++; |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 1022 | |
| 1023 | memcpy(pos, data, data_len); |
| 1024 | len += data_len; |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 1025 | if (header) |
| 1026 | header->length += len; |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 1027 | |
| 1028 | return len; |
| 1029 | } |
| 1030 | |
| 1031 | /* ACPI 4.0 */ |
Vladimir Serbinenko | 807127f | 2014-11-09 13:36:18 +0100 | [diff] [blame] | 1032 | void acpi_write_hest(acpi_hest_t *hest, |
| 1033 | unsigned long (*acpi_fill_hest)(acpi_hest_t *hest)) |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 1034 | { |
| 1035 | acpi_header_t *header = &(hest->header); |
| 1036 | |
| 1037 | memset(hest, 0, sizeof(acpi_hest_t)); |
| 1038 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 1039 | if (acpi_fill_header(header, "HEST", HEST, sizeof(acpi_hest_t)) != CB_SUCCESS) |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 1040 | return; |
| 1041 | |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 1042 | acpi_fill_hest(hest); |
| 1043 | |
| 1044 | /* Calculate checksums. */ |
| 1045 | header->checksum = acpi_checksum((void *)hest, header->length); |
| 1046 | } |
| 1047 | |
Marshall Dawson | 1d8d369 | 2018-09-04 13:45:26 -0600 | [diff] [blame] | 1048 | /* ACPI 3.0b */ |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1049 | static void acpi_create_bert(acpi_header_t *header, void *unused) |
Marshall Dawson | 1d8d369 | 2018-09-04 13:45:26 -0600 | [diff] [blame] | 1050 | { |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1051 | if (!CONFIG(ACPI_BERT)) |
| 1052 | return; |
Marshall Dawson | 1d8d369 | 2018-09-04 13:45:26 -0600 | [diff] [blame] | 1053 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1054 | acpi_bert_t *bert = (acpi_bert_t *)header; |
Marshall Dawson | 1d8d369 | 2018-09-04 13:45:26 -0600 | [diff] [blame] | 1055 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1056 | void *region; |
| 1057 | size_t size; |
| 1058 | if (acpi_soc_get_bert_region(®ion, &size) != CB_SUCCESS) |
| 1059 | return; |
| 1060 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 1061 | if (acpi_fill_header(header, "BERT", BERT, sizeof(acpi_bert_t)) != CB_SUCCESS) |
| 1062 | return; |
Marshall Dawson | 1d8d369 | 2018-09-04 13:45:26 -0600 | [diff] [blame] | 1063 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1064 | bert->error_region = (uintptr_t)region; |
| 1065 | bert->region_length = (size_t)size; |
Marshall Dawson | 1d8d369 | 2018-09-04 13:45:26 -0600 | [diff] [blame] | 1066 | } |
| 1067 | |
Angel Pons | 79572e4 | 2020-07-13 00:17:43 +0200 | [diff] [blame] | 1068 | __weak void arch_fill_fadt(acpi_fadt_t *fadt) { } |
Kyösti Mälkki | f9aac92 | 2020-05-30 16:16:28 +0300 | [diff] [blame] | 1069 | __weak void soc_fill_fadt(acpi_fadt_t *fadt) { } |
Kyösti Mälkki | 02fd15d | 2020-06-02 03:34:43 +0300 | [diff] [blame] | 1070 | __weak void mainboard_fill_fadt(acpi_fadt_t *fadt) { } |
Kyösti Mälkki | f9aac92 | 2020-05-30 16:16:28 +0300 | [diff] [blame] | 1071 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1072 | static acpi_header_t *dsdt; |
| 1073 | static void acpi_create_fadt(acpi_header_t *header, void *arg1) |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1074 | { |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1075 | acpi_fadt_t *fadt = (acpi_fadt_t *)header; |
| 1076 | acpi_facs_t *facs = (acpi_facs_t *)(*(acpi_facs_t **)arg1); |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 1077 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 1078 | if (acpi_fill_header(header, "FACP", FADT, sizeof(acpi_fadt_t)) != CB_SUCCESS) |
John Zhao | 2ba303e | 2019-05-28 16:48:14 -0700 | [diff] [blame] | 1079 | return; |
| 1080 | |
Elyes Haouas | 532e043 | 2022-02-21 18:13:58 +0100 | [diff] [blame] | 1081 | fadt->FADT_MinorVersion = get_acpi_fadt_minor_version(); |
Arthur Heymans | 8473e8f | 2023-06-29 20:26:39 +0200 | [diff] [blame] | 1082 | if ((uintptr_t)facs <= UINT32_MAX) |
| 1083 | fadt->firmware_ctrl = (uintptr_t)facs; |
| 1084 | else |
| 1085 | fadt->x_firmware_ctl_h = (uint32_t)((uint64_t)(uintptr_t)facs >> 32); |
| 1086 | fadt->x_firmware_ctl_l = (uint32_t)(uintptr_t)facs; |
Kyösti Mälkki | d4acee8 | 2020-06-03 07:20:55 +0300 | [diff] [blame] | 1087 | |
Arthur Heymans | 8473e8f | 2023-06-29 20:26:39 +0200 | [diff] [blame] | 1088 | if ((uintptr_t)dsdt <= UINT32_MAX) |
| 1089 | fadt->dsdt = (uintptr_t)dsdt; |
| 1090 | else |
| 1091 | fadt->x_dsdt_h = (uint32_t)((uint64_t)(uintptr_t)dsdt >> 32); |
| 1092 | fadt->x_dsdt_l = (uint32_t)(uintptr_t)dsdt; |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1093 | |
Kyösti Mälkki | d4acee8 | 2020-06-03 07:20:55 +0300 | [diff] [blame] | 1094 | /* should be 0 ACPI 3.0 */ |
| 1095 | fadt->reserved = 0; |
| 1096 | |
Kyösti Mälkki | 67c48a3 | 2023-04-14 10:20:03 +0300 | [diff] [blame] | 1097 | /* P_LVLx latencies are not used as CPU _CST will override them. */ |
| 1098 | fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED; |
| 1099 | fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED; |
| 1100 | |
Kyösti Mälkki | 9ff9797 | 2023-04-14 15:37:27 +0300 | [diff] [blame] | 1101 | /* Use CPU _PTC instead to provide P_CNT details. */ |
| 1102 | fadt->duty_offset = 0; |
| 1103 | fadt->duty_width = 0; |
| 1104 | |
Kyösti Mälkki | e0d3868 | 2020-06-07 12:01:58 +0300 | [diff] [blame] | 1105 | fadt->preferred_pm_profile = acpi_get_preferred_pm_profile(); |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1106 | |
Angel Pons | 79572e4 | 2020-07-13 00:17:43 +0200 | [diff] [blame] | 1107 | arch_fill_fadt(fadt); |
| 1108 | |
Vladimir Serbinenko | ab83ef0 | 2014-10-25 15:18:25 +0200 | [diff] [blame] | 1109 | acpi_fill_fadt(fadt); |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1110 | |
Kyösti Mälkki | f9aac92 | 2020-05-30 16:16:28 +0300 | [diff] [blame] | 1111 | soc_fill_fadt(fadt); |
Kyösti Mälkki | 02fd15d | 2020-06-02 03:34:43 +0300 | [diff] [blame] | 1112 | mainboard_fill_fadt(fadt); |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1113 | } |
Vladimir Serbinenko | c21e073 | 2014-10-16 12:48:19 +0200 | [diff] [blame] | 1114 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1115 | static void acpi_create_lpit(acpi_header_t *header, void *unused) |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1116 | { |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1117 | if (!CONFIG(ACPI_LPIT)) |
| 1118 | return; |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1119 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1120 | acpi_lpit_t *lpit = (acpi_lpit_t *)header; |
| 1121 | unsigned long current = (unsigned long)lpit + sizeof(acpi_lpit_t); |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1122 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 1123 | if (acpi_fill_header(header, "LPIT", LPIT, sizeof(acpi_lpit_t)) != CB_SUCCESS) |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1124 | return; |
| 1125 | |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1126 | current = acpi_fill_lpit(current); |
| 1127 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1128 | /* (Re)calculate length. */ |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1129 | header->length = current - (unsigned long)lpit; |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1130 | } |
| 1131 | |
Arthur Heymans | 2e3cb63 | 2023-06-30 15:01:08 +0200 | [diff] [blame] | 1132 | static void acpi_create_gtdt(acpi_header_t *header, void *unused) |
| 1133 | { |
| 1134 | if (!CONFIG(ACPI_GTDT)) |
| 1135 | return; |
| 1136 | |
| 1137 | acpi_gtdt_t *gtdt = (acpi_gtdt_t *)header; |
| 1138 | unsigned long current = (unsigned long)gtdt + sizeof(acpi_gtdt_t); |
| 1139 | |
| 1140 | if (acpi_fill_header(header, "GTDT", GTDT, sizeof(acpi_gtdt_t)) != CB_SUCCESS) |
| 1141 | return; |
| 1142 | |
| 1143 | /* Fill out header fields. */ |
| 1144 | gtdt->platform_timer_offset = sizeof(acpi_gtdt_t); |
| 1145 | |
| 1146 | acpi_soc_fill_gtdt(gtdt); |
| 1147 | current = acpi_soc_gtdt_add_timers(>dt->platform_timer_count, current); |
| 1148 | |
| 1149 | /* (Re)calculate length. */ |
| 1150 | header->length = current - (unsigned long)gtdt; |
| 1151 | } |
| 1152 | |
| 1153 | unsigned long acpi_gtdt_add_timer_block(unsigned long current, const uint64_t address, |
| 1154 | struct acpi_gtdt_timer_entry *timers, size_t number) |
| 1155 | { |
| 1156 | struct acpi_gtdt_timer_block *block = (struct acpi_gtdt_timer_block *)current; |
| 1157 | memset(block, 0, sizeof(struct acpi_gtdt_timer_block)); |
| 1158 | |
| 1159 | assert(number < 8 && number != 0); |
| 1160 | const size_t entries_size = number * sizeof(struct acpi_gtdt_timer_entry); |
| 1161 | |
| 1162 | block->header.type = ACPI_GTDT_TYPE_TIMER_BLOCK; |
| 1163 | block->header.length = sizeof(struct acpi_gtdt_timer_block) |
| 1164 | + entries_size; |
| 1165 | block->block_address = address; |
| 1166 | block->timer_count = number; |
| 1167 | block->timer_offset = sizeof(struct acpi_gtdt_timer_block); |
| 1168 | current += sizeof(struct acpi_gtdt_timer_block); |
| 1169 | memcpy((void *)current, timers, entries_size); |
| 1170 | current += entries_size; |
| 1171 | return current; |
| 1172 | } |
| 1173 | |
| 1174 | unsigned long acpi_gtdt_add_watchdog(unsigned long current, uint64_t refresh_frame, |
| 1175 | uint64_t control_frame, uint32_t gsiv, uint32_t flags) |
| 1176 | { |
| 1177 | struct acpi_gtdt_watchdog *wd = (struct acpi_gtdt_watchdog *)current; |
| 1178 | memset(wd, 0, sizeof(struct acpi_gtdt_watchdog)); |
| 1179 | |
| 1180 | wd->header.type = ACPI_GTDT_TYPE_WATCHDOG; |
| 1181 | wd->header.length = sizeof(struct acpi_gtdt_watchdog); |
| 1182 | wd->refresh_frame_address = refresh_frame; |
| 1183 | wd->control_frame_address = control_frame; |
| 1184 | wd->timer_interrupt = gsiv; |
| 1185 | wd->timer_flags = flags; |
| 1186 | |
| 1187 | return current + sizeof(struct acpi_gtdt_watchdog); |
| 1188 | } |
| 1189 | |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1190 | unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid) |
| 1191 | { |
| 1192 | memset(lpi_desc, 0, sizeof(acpi_lpi_desc_ncst_t)); |
| 1193 | lpi_desc->header.length = sizeof(acpi_lpi_desc_ncst_t); |
| 1194 | lpi_desc->header.type = ACPI_LPI_DESC_TYPE_NATIVE_CSTATE; |
| 1195 | lpi_desc->header.uid = uid; |
| 1196 | |
| 1197 | return lpi_desc->header.length; |
| 1198 | } |
| 1199 | |
Arthur Heymans | 9046407 | 2023-06-07 12:53:50 +0200 | [diff] [blame] | 1200 | static uint8_t acpi_spcr_type(void) |
| 1201 | { |
| 1202 | /* 16550-compatible with parameters defined in Generic Address Structure */ |
| 1203 | if (CONFIG(DRIVERS_UART_8250IO) || CONFIG(DRIVERS_UART_8250MEM)) |
| 1204 | return 0x12; |
| 1205 | if (CONFIG(DRIVERS_UART_PL011)) |
| 1206 | return 0x3; |
| 1207 | |
| 1208 | printk(BIOS_ERR, "%s: unknown serial type\n", __func__); |
| 1209 | return 0xff; |
| 1210 | } |
| 1211 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1212 | static void acpi_create_spcr(acpi_header_t *header, void *unused) |
Arthur Heymans | 9046407 | 2023-06-07 12:53:50 +0200 | [diff] [blame] | 1213 | { |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1214 | acpi_spcr_t *spcr = (acpi_spcr_t *)header; |
Arthur Heymans | 9046407 | 2023-06-07 12:53:50 +0200 | [diff] [blame] | 1215 | struct lb_serial serial; |
| 1216 | |
Arthur Heymans | 9046407 | 2023-06-07 12:53:50 +0200 | [diff] [blame] | 1217 | if (!CONFIG(CONSOLE_SERIAL)) |
| 1218 | return; |
| 1219 | |
| 1220 | if (fill_lb_serial(&serial) != CB_SUCCESS) |
| 1221 | return; |
| 1222 | |
Arthur Heymans | adb8007 | 2023-06-28 09:56:00 +0200 | [diff] [blame] | 1223 | if (acpi_fill_header(header, "SPCR", SPCR, sizeof(acpi_spcr_t)) != CB_SUCCESS) |
| 1224 | return; |
Arthur Heymans | 9046407 | 2023-06-07 12:53:50 +0200 | [diff] [blame] | 1225 | |
| 1226 | spcr->interface_type = acpi_spcr_type(); |
| 1227 | assert(serial.type == LB_SERIAL_TYPE_IO_MAPPED |
| 1228 | || serial.type == LB_SERIAL_TYPE_MEMORY_MAPPED); |
| 1229 | spcr->base_address.space_id = serial.type == LB_SERIAL_TYPE_IO_MAPPED ? |
| 1230 | ACPI_ADDRESS_SPACE_IO : ACPI_ADDRESS_SPACE_MEMORY; |
| 1231 | spcr->base_address.bit_width = serial.regwidth * 8; |
| 1232 | spcr->base_address.bit_offset = 0; |
| 1233 | switch (serial.regwidth) { |
| 1234 | case 1: |
| 1235 | spcr->base_address.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
| 1236 | break; |
| 1237 | case 2: |
| 1238 | spcr->base_address.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
| 1239 | break; |
| 1240 | case 4: |
| 1241 | spcr->base_address.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 1242 | break; |
| 1243 | default: |
| 1244 | printk(BIOS_ERR, "%s, Invalid serial regwidth\n", __func__); |
| 1245 | } |
| 1246 | |
| 1247 | spcr->base_address.addrl = serial.baseaddr; |
| 1248 | spcr->base_address.addrh = 0; |
| 1249 | spcr->interrupt_type = 0; |
| 1250 | spcr->irq = 0; |
| 1251 | spcr->configured_baudrate = 0; /* Have the OS use whatever is currently set */ |
| 1252 | spcr->parity = 0; |
| 1253 | spcr->stop_bits = 1; |
| 1254 | spcr->flow_control = 0; |
| 1255 | spcr->terminal_type = 2; /* 2 = VT-UTF8 */ |
| 1256 | spcr->language = 0; |
| 1257 | spcr->pci_did = 0xffff; |
| 1258 | spcr->pci_vid = 0xffff; |
Nico Huber | feb27dc | 2023-06-28 20:09:30 +0200 | [diff] [blame] | 1259 | |
| 1260 | header->checksum = acpi_checksum((void *)spcr, header->length); |
Arthur Heymans | 9046407 | 2023-06-07 12:53:50 +0200 | [diff] [blame] | 1261 | } |
| 1262 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 1263 | unsigned long __weak fw_cfg_acpi_tables(unsigned long start) |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 1264 | { |
| 1265 | return 0; |
| 1266 | } |
| 1267 | |
Raul E Rangel | 6b446b9 | 2021-11-19 11:38:35 -0700 | [diff] [blame] | 1268 | void preload_acpi_dsdt(void) |
| 1269 | { |
| 1270 | const char *file = CONFIG_CBFS_PREFIX "/dsdt.aml"; |
| 1271 | |
| 1272 | if (!CONFIG(CBFS_PRELOAD)) |
| 1273 | return; |
| 1274 | |
| 1275 | printk(BIOS_DEBUG, "Preloading %s\n", file); |
| 1276 | cbfs_preload(file); |
| 1277 | } |
| 1278 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1279 | static void acpi_create_dsdt(acpi_header_t *header, void *dsdt_file_arg) |
| 1280 | { |
| 1281 | dsdt = header; |
| 1282 | acpi_header_t *dsdt_file = *(acpi_header_t **)dsdt_file_arg; |
| 1283 | unsigned long current = (unsigned long)header; |
| 1284 | |
| 1285 | dsdt = (acpi_header_t *)current; |
| 1286 | memcpy(dsdt, dsdt_file, sizeof(acpi_header_t)); |
| 1287 | if (dsdt->length >= sizeof(acpi_header_t)) { |
| 1288 | current += sizeof(acpi_header_t); |
| 1289 | |
| 1290 | acpigen_set_current((char *)current); |
| 1291 | |
| 1292 | if (CONFIG(ACPI_SOC_NVS)) |
| 1293 | acpi_fill_gnvs(); |
| 1294 | if (CONFIG(CHROMEOS_NVS)) |
| 1295 | acpi_fill_cnvs(); |
| 1296 | |
| 1297 | for (const struct device *dev = all_devices; dev; dev = dev->next) |
| 1298 | if (dev->ops && dev->ops->acpi_inject_dsdt) |
| 1299 | dev->ops->acpi_inject_dsdt(dev); |
| 1300 | current = (unsigned long)acpigen_get_current(); |
| 1301 | memcpy((char *)current, |
| 1302 | (char *)dsdt_file + sizeof(acpi_header_t), |
| 1303 | dsdt->length - sizeof(acpi_header_t)); |
| 1304 | current += dsdt->length - sizeof(acpi_header_t); |
| 1305 | |
| 1306 | /* (Re)calculate length. */ |
| 1307 | dsdt->length = current - (unsigned long)dsdt; |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | static void acpi_create_slic(acpi_header_t *header, void *slic_file_arg) |
| 1312 | { |
| 1313 | acpi_header_t *slic_file = *(acpi_header_t **)slic_file_arg; |
| 1314 | acpi_header_t *slic = header; |
| 1315 | if (slic_file) |
| 1316 | memcpy(slic, slic_file, slic_file->length); |
| 1317 | } |
| 1318 | |
Arthur Heymans | 2e7e2d9 | 2022-03-03 22:28:27 +0100 | [diff] [blame] | 1319 | static uintptr_t coreboot_rsdp; |
| 1320 | |
| 1321 | uintptr_t get_coreboot_rsdp(void) |
| 1322 | { |
| 1323 | return coreboot_rsdp; |
| 1324 | } |
| 1325 | |
Arthur Heymans | 0ad766c | 2023-06-07 10:45:59 +0200 | [diff] [blame] | 1326 | static void acpixtract_compatible_hexdump(const void *memory, size_t length) |
| 1327 | { |
| 1328 | size_t i, j; |
| 1329 | uint8_t *line; |
| 1330 | size_t num_bytes; |
| 1331 | |
| 1332 | for (i = 0; i < length; i += 16) { |
| 1333 | num_bytes = MIN(length - i, 16); |
| 1334 | line = ((uint8_t *)memory) + i; |
| 1335 | |
| 1336 | printk(BIOS_SPEW, " %04zX:", i); |
| 1337 | for (j = 0; j < num_bytes; j++) |
| 1338 | printk(BIOS_SPEW, " %02x", line[j]); |
| 1339 | for (; j < 16; j++) |
| 1340 | printk(BIOS_SPEW, " "); |
| 1341 | printk(BIOS_SPEW, " "); |
| 1342 | for (j = 0; j < num_bytes; j++) |
| 1343 | printk(BIOS_SPEW, "%c", |
| 1344 | isprint(line[j]) ? line[j] : '.'); |
| 1345 | printk(BIOS_SPEW, "\n"); |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | static void acpidump_print(void *table_ptr) |
| 1350 | { |
| 1351 | const acpi_header_t *header = (acpi_header_t *)table_ptr; |
| 1352 | const size_t table_size = header->length; |
| 1353 | printk(BIOS_SPEW, "%.4s @ 0x0000000000000000\n", header->signature); |
| 1354 | acpixtract_compatible_hexdump(table_ptr, table_size); |
| 1355 | printk(BIOS_SPEW, "\n"); |
| 1356 | } |
| 1357 | |
Arthur Heymans | 7ebebf7 | 2023-06-17 14:08:46 +0200 | [diff] [blame] | 1358 | unsigned long write_acpi_tables(const unsigned long start) |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1359 | { |
| 1360 | unsigned long current; |
| 1361 | acpi_rsdp_t *rsdp; |
Arthur Heymans | 0ad766c | 2023-06-07 10:45:59 +0200 | [diff] [blame] | 1362 | acpi_rsdt_t *rsdt = NULL; |
| 1363 | acpi_xsdt_t *xsdt = NULL; |
Arthur Heymans | 0ad766c | 2023-06-07 10:45:59 +0200 | [diff] [blame] | 1364 | acpi_facs_t *facs = NULL; |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1365 | acpi_header_t *slic_file; |
Arthur Heymans | 0ad766c | 2023-06-07 10:45:59 +0200 | [diff] [blame] | 1366 | acpi_header_t *ssdt = NULL; |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1367 | acpi_header_t *dsdt_file; |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 1368 | struct device *dev; |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 1369 | unsigned long fw; |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1370 | size_t slic_size, dsdt_size; |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1371 | char oem_id[6], oem_table_id[8]; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1372 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1373 | const struct acpi_table_generator { |
| 1374 | void (*create_table)(acpi_header_t *table, void *arg); |
| 1375 | void *args; |
| 1376 | size_t min_size; |
| 1377 | } tables[] = { |
| 1378 | { acpi_create_dsdt, &dsdt_file, sizeof(acpi_header_t) }, |
| 1379 | { acpi_create_fadt, &facs, sizeof(acpi_fadt_t) }, |
| 1380 | { acpi_create_slic, &slic_file, sizeof(acpi_header_t) }, |
| 1381 | { acpi_create_ssdt_generator, NULL, sizeof(acpi_header_t) }, |
| 1382 | { acpi_create_mcfg, NULL, sizeof(acpi_mcfg_t) }, |
| 1383 | { acpi_create_tcpa, NULL, sizeof(acpi_tcpa_t) }, |
| 1384 | { acpi_create_tpm2, NULL, sizeof(acpi_tpm2_t) }, |
| 1385 | { acpi_create_lpit, NULL, sizeof(acpi_lpit_t) }, |
| 1386 | { acpi_create_madt, NULL, sizeof(acpi_header_t) }, |
| 1387 | { acpi_create_bert, NULL, sizeof(acpi_bert_t) }, |
| 1388 | { acpi_create_spcr, NULL, sizeof(acpi_spcr_t) }, |
Arthur Heymans | 2e3cb63 | 2023-06-30 15:01:08 +0200 | [diff] [blame] | 1389 | { acpi_create_gtdt, NULL, sizeof(acpi_gtdt_t) }, |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1390 | }; |
| 1391 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1392 | current = start; |
| 1393 | |
| 1394 | /* Align ACPI tables to 16byte */ |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1395 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1396 | |
Patrick Rudolph | cfe08ff | 2019-09-10 15:40:47 +0200 | [diff] [blame] | 1397 | /* Special case for qemu */ |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 1398 | fw = fw_cfg_acpi_tables(current); |
Patrick Rudolph | cfe08ff | 2019-09-10 15:40:47 +0200 | [diff] [blame] | 1399 | if (fw) { |
| 1400 | rsdp = NULL; |
| 1401 | /* Find RSDP. */ |
| 1402 | for (void *p = (void *)current; p < (void *)fw; p += 16) { |
| 1403 | if (valid_rsdp((acpi_rsdp_t *)p)) { |
| 1404 | rsdp = p; |
Bin Meng | f3027b8 | 2023-05-09 15:21:49 +0800 | [diff] [blame] | 1405 | coreboot_rsdp = (uintptr_t)rsdp; |
Patrick Rudolph | cfe08ff | 2019-09-10 15:40:47 +0200 | [diff] [blame] | 1406 | break; |
| 1407 | } |
| 1408 | } |
| 1409 | if (!rsdp) |
| 1410 | return fw; |
| 1411 | |
| 1412 | /* Add BOOT0000 for Linux google firmware driver */ |
| 1413 | printk(BIOS_DEBUG, "ACPI: * SSDT\n"); |
| 1414 | ssdt = (acpi_header_t *)fw; |
| 1415 | current = (unsigned long)ssdt + sizeof(acpi_header_t); |
| 1416 | |
| 1417 | memset((void *)ssdt, 0, sizeof(acpi_header_t)); |
| 1418 | |
| 1419 | memcpy(&ssdt->signature, "SSDT", 4); |
| 1420 | ssdt->revision = get_acpi_table_revision(SSDT); |
| 1421 | memcpy(&ssdt->oem_id, OEM_ID, 6); |
| 1422 | memcpy(&ssdt->oem_table_id, oem_table_id, 8); |
| 1423 | ssdt->oem_revision = 42; |
| 1424 | memcpy(&ssdt->asl_compiler_id, ASLC, 4); |
| 1425 | ssdt->asl_compiler_revision = asl_revision; |
| 1426 | ssdt->length = sizeof(acpi_header_t); |
| 1427 | |
Elyes Haouas | 3141fbad | 2022-11-18 15:22:32 +0100 | [diff] [blame] | 1428 | acpigen_set_current((char *)current); |
Patrick Rudolph | cfe08ff | 2019-09-10 15:40:47 +0200 | [diff] [blame] | 1429 | |
| 1430 | /* Write object to declare coreboot tables */ |
| 1431 | acpi_ssdt_write_cbtable(); |
| 1432 | |
| 1433 | /* (Re)calculate length and checksum. */ |
| 1434 | ssdt->length = current - (unsigned long)ssdt; |
| 1435 | ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length); |
| 1436 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1437 | acpi_create_ssdt_generator(ssdt, NULL); |
Patrick Rudolph | cfe08ff | 2019-09-10 15:40:47 +0200 | [diff] [blame] | 1438 | |
| 1439 | acpi_add_table(rsdp, ssdt); |
| 1440 | |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 1441 | return fw; |
Patrick Rudolph | cfe08ff | 2019-09-10 15:40:47 +0200 | [diff] [blame] | 1442 | } |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 1443 | |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame] | 1444 | dsdt_file = cbfs_map(CONFIG_CBFS_PREFIX "/dsdt.aml", &dsdt_size); |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1445 | if (!dsdt_file) { |
| 1446 | printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n"); |
Arthur Heymans | 0600aa6 | 2023-06-17 14:13:54 +0200 | [diff] [blame] | 1447 | return start; |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | if (dsdt_file->length > dsdt_size |
Elyes HAOUAS | 7d87e76 | 2016-10-03 22:11:07 +0200 | [diff] [blame] | 1451 | || dsdt_file->length < sizeof(acpi_header_t) |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1452 | || memcmp(dsdt_file->signature, "DSDT", 4) != 0) { |
| 1453 | printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n"); |
Grzegorz Bernacki | 042ac35 | 2023-04-21 13:19:58 +0000 | [diff] [blame] | 1454 | cbfs_unmap(dsdt_file); |
Arthur Heymans | 0600aa6 | 2023-06-17 14:13:54 +0200 | [diff] [blame] | 1455 | return start; |
Vladimir Serbinenko | 36f8d27 | 2015-05-31 12:31:59 +0200 | [diff] [blame] | 1456 | } |
| 1457 | |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame] | 1458 | slic_file = cbfs_map(CONFIG_CBFS_PREFIX "/slic", &slic_size); |
Vladimir Serbinenko | 2cb2978 | 2015-05-31 11:32:09 +0200 | [diff] [blame] | 1459 | if (slic_file |
| 1460 | && (slic_file->length > slic_size |
Elyes HAOUAS | 7d87e76 | 2016-10-03 22:11:07 +0200 | [diff] [blame] | 1461 | || slic_file->length < sizeof(acpi_header_t) |
Benjamin Doron | 2b2dc0c | 2020-09-12 02:55:57 +0000 | [diff] [blame] | 1462 | || (memcmp(slic_file->signature, "SLIC", 4) != 0 |
| 1463 | && memcmp(slic_file->signature, "MSDM", 4) != 0))) { |
Grzegorz Bernacki | 042ac35 | 2023-04-21 13:19:58 +0000 | [diff] [blame] | 1464 | cbfs_unmap(slic_file); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1465 | slic_file = 0; |
| 1466 | } |
| 1467 | |
| 1468 | if (slic_file) { |
| 1469 | memcpy(oem_id, slic_file->oem_id, 6); |
| 1470 | memcpy(oem_table_id, slic_file->oem_table_id, 8); |
| 1471 | } else { |
| 1472 | memcpy(oem_id, OEM_ID, 6); |
| 1473 | memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 1474 | } |
| 1475 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1476 | printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start); |
| 1477 | |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 1478 | /* We need at least an RSDP, RSDT for ACPI 1.0 compat, otherwise XSDT */ |
Elyes Haouas | 3141fbad | 2022-11-18 15:22:32 +0100 | [diff] [blame] | 1479 | rsdp = (acpi_rsdp_t *)current; |
Arthur Heymans | 2e7e2d9 | 2022-03-03 22:28:27 +0100 | [diff] [blame] | 1480 | coreboot_rsdp = (uintptr_t)rsdp; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1481 | current += sizeof(acpi_rsdp_t); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1482 | current = acpi_align_current(current); |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 1483 | if (current + sizeof(acpi_rsdt_t) - 1 <= UINT32_MAX) { |
| 1484 | rsdt = (acpi_rsdt_t *)current; |
| 1485 | current += sizeof(acpi_rsdt_t); |
| 1486 | current = acpi_align_current(current); |
| 1487 | } else { |
| 1488 | printk(BIOS_INFO, "Not adding RSDT because tables reside above 4G."); |
| 1489 | } |
| 1490 | |
Elyes Haouas | 3141fbad | 2022-11-18 15:22:32 +0100 | [diff] [blame] | 1491 | xsdt = (acpi_xsdt_t *)current; |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1492 | current += sizeof(acpi_xsdt_t); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1493 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1494 | |
| 1495 | /* clear all table memory */ |
Elyes Haouas | 3141fbad | 2022-11-18 15:22:32 +0100 | [diff] [blame] | 1496 | memset((void *)start, 0, current - start); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1497 | |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1498 | acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id); |
| 1499 | acpi_write_rsdt(rsdt, oem_id, oem_table_id); |
| 1500 | acpi_write_xsdt(xsdt, oem_id, oem_table_id); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1501 | |
Arthur Heymans | 6af7261 | 2023-06-29 20:25:32 +0200 | [diff] [blame] | 1502 | if (ENV_X86) { |
| 1503 | printk(BIOS_DEBUG, "ACPI: * FACS\n"); |
| 1504 | current = ALIGN_UP(current, 64); |
| 1505 | facs = (acpi_facs_t *)current; |
| 1506 | current += sizeof(acpi_facs_t); |
| 1507 | current = acpi_align_current(current); |
| 1508 | acpi_create_facs(facs); |
| 1509 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1510 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1511 | for (size_t i = 0; i < ARRAY_SIZE(tables); i++) { |
| 1512 | acpi_header_t *header = (acpi_header_t *)current; |
| 1513 | memset(header, 0, tables[i].min_size); |
| 1514 | tables[i].create_table(header, tables[i].args); |
| 1515 | if (header->length < tables[i].min_size) |
| 1516 | continue; |
| 1517 | header->checksum = 0; |
| 1518 | header->checksum = acpi_checksum((void *)header, header->length); |
| 1519 | current += header->length; |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1520 | current = acpi_align_current(current); |
Kyösti Mälkki | 0bcdd40 | 2023-07-06 14:47:07 +0300 | [diff] [blame] | 1521 | |
| 1522 | if (tables[i].create_table == acpi_create_dsdt) |
| 1523 | continue; |
| 1524 | |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1525 | printk(BIOS_DEBUG, "ACPI: * %.4s\n", header->signature); |
| 1526 | acpi_add_table(rsdp, header); |
Vladimir Serbinenko | 351fefc | 2014-10-26 20:42:08 +0100 | [diff] [blame] | 1527 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1528 | |
Grzegorz Bernacki | 042ac35 | 2023-04-21 13:19:58 +0000 | [diff] [blame] | 1529 | /* |
| 1530 | * cbfs_unmap() uses mem_pool_free() which works correctly only |
| 1531 | * if freeing is done in reverse order than memory allocation. |
| 1532 | * This is why unmapping of dsdt_file must be done after |
| 1533 | * unmapping slic file. |
| 1534 | */ |
Arthur Heymans | 01af0f8 | 2023-06-27 11:58:04 +0200 | [diff] [blame] | 1535 | cbfs_unmap(slic_file); |
Grzegorz Bernacki | 042ac35 | 2023-04-21 13:19:58 +0000 | [diff] [blame] | 1536 | cbfs_unmap(dsdt_file); |
| 1537 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1538 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 1539 | |
| 1540 | for (dev = all_devices; dev; dev = dev->next) { |
| 1541 | if (dev->ops && dev->ops->write_acpi_tables) { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 1542 | current = dev->ops->write_acpi_tables(dev, current, |
| 1543 | rsdp); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 1544 | current = acpi_align_current(current); |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | printk(BIOS_INFO, "ACPI: done.\n"); |
Arthur Heymans | 0ad766c | 2023-06-07 10:45:59 +0200 | [diff] [blame] | 1549 | |
| 1550 | if (CONFIG(DEBUG_ACPICA_COMPATIBLE)) { |
| 1551 | printk(BIOS_DEBUG, "Printing ACPI tables in ACPICA compatible format\n"); |
Arthur Heymans | 1cdeaea | 2023-07-06 16:24:50 +0200 | [diff] [blame] | 1552 | if (facs) |
| 1553 | acpidump_print(facs); |
| 1554 | acpidump_print(dsdt); |
Arthur Heymans | 3e523b4 | 2023-06-15 17:04:16 +0200 | [diff] [blame] | 1555 | for (size_t i = 0; xsdt->entry[i] != 0; i++) { |
| 1556 | acpidump_print((void *)(uintptr_t)xsdt->entry[i]); |
Arthur Heymans | 0ad766c | 2023-06-07 10:45:59 +0200 | [diff] [blame] | 1557 | } |
| 1558 | printk(BIOS_DEBUG, "Done printing ACPI tables in ACPICA compatible format\n"); |
| 1559 | } |
| 1560 | |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1561 | return current; |
| 1562 | } |
Vladimir Serbinenko | 2d7bd8a | 2014-08-30 19:28:05 +0200 | [diff] [blame] | 1563 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1564 | static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp) |
| 1565 | { |
| 1566 | if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0) |
| 1567 | return NULL; |
| 1568 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1569 | printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1570 | |
| 1571 | if (acpi_checksum((void *)rsdp, 20) != 0) |
| 1572 | return NULL; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1573 | printk(BIOS_DEBUG, "Checksum 1 passed\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1574 | |
| 1575 | if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp, |
| 1576 | rsdp->length) != 0)) |
| 1577 | return NULL; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1578 | printk(BIOS_DEBUG, "Checksum 2 passed all OK\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1579 | |
| 1580 | return rsdp; |
| 1581 | } |
| 1582 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1583 | void *acpi_find_wakeup_vector(void) |
| 1584 | { |
| 1585 | char *p, *end; |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 1586 | acpi_xsdt_t *xsdt; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1587 | acpi_facs_t *facs; |
Martin Roth | c5f4926 | 2012-12-14 19:17:55 -0700 | [diff] [blame] | 1588 | acpi_fadt_t *fadt = NULL; |
Kyösti Mälkki | 072d436b | 2016-06-17 08:44:40 +0300 | [diff] [blame] | 1589 | acpi_rsdp_t *rsdp = NULL; |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1590 | void *wake_vec; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1591 | int i; |
| 1592 | |
Kyösti Mälkki | b8c7ea0 | 2020-11-17 16:41:38 +0200 | [diff] [blame] | 1593 | if (!acpi_is_wakeup_s3()) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1594 | return NULL; |
| 1595 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1596 | printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1597 | |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1598 | /* Find RSDP. */ |
| 1599 | for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) { |
Lee Leahy | 0b5678f | 2017-03-16 16:01:40 -0700 | [diff] [blame] | 1600 | rsdp = valid_rsdp((acpi_rsdp_t *)p); |
| 1601 | if (rsdp) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1602 | break; |
| 1603 | } |
| 1604 | |
Angel Pons | 98a68ad | 2018-11-04 12:25:25 +0100 | [diff] [blame] | 1605 | if (rsdp == NULL) { |
| 1606 | printk(BIOS_ALERT, |
| 1607 | "No RSDP found, wake up from S3 not possible.\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1608 | return NULL; |
Angel Pons | 98a68ad | 2018-11-04 12:25:25 +0100 | [diff] [blame] | 1609 | } |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1610 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1611 | printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp); |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 1612 | xsdt = (acpi_xsdt_t *)(uintptr_t)rsdp->xsdt_address; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 1613 | |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 1614 | end = (char *)xsdt + xsdt->header.length; |
| 1615 | printk(BIOS_DEBUG, "XSDT found at %p ends at %p\n", xsdt, end); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1616 | |
Arthur Heymans | d8f2dce | 2023-06-22 13:42:36 +0200 | [diff] [blame] | 1617 | for (i = 0; ((char *)&xsdt->entry[i]) < end; i++) { |
| 1618 | fadt = (acpi_fadt_t *)(uintptr_t)xsdt->entry[i]; |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 1619 | if (strncmp((char *)fadt, "FACP", 4) == 0) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1620 | break; |
| 1621 | fadt = NULL; |
| 1622 | } |
| 1623 | |
Angel Pons | 98a68ad | 2018-11-04 12:25:25 +0100 | [diff] [blame] | 1624 | if (fadt == NULL) { |
| 1625 | printk(BIOS_ALERT, |
| 1626 | "No FADT found, wake up from S3 not possible.\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1627 | return NULL; |
Angel Pons | 98a68ad | 2018-11-04 12:25:25 +0100 | [diff] [blame] | 1628 | } |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1629 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1630 | printk(BIOS_DEBUG, "FADT found at %p\n", fadt); |
Arthur Heymans | a07b09a | 2023-07-05 12:53:10 +0200 | [diff] [blame] | 1631 | facs = (acpi_facs_t *)(uintptr_t)((uint64_t)fadt->x_firmware_ctl_l |
| 1632 | | (uint64_t)fadt->x_firmware_ctl_h << 32); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1633 | |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 1634 | if (facs == NULL) { |
Angel Pons | 98a68ad | 2018-11-04 12:25:25 +0100 | [diff] [blame] | 1635 | printk(BIOS_ALERT, |
| 1636 | "No FACS found, wake up from S3 not possible.\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1637 | return NULL; |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 1638 | } |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1639 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1640 | printk(BIOS_DEBUG, "FACS found at %p\n", facs); |
Stefan Reinauer | 71a3018 | 2015-07-30 16:28:13 -0700 | [diff] [blame] | 1641 | wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1642 | printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec); |
Uwe Hermann | 622824c | 2010-11-19 15:14:42 +0000 | [diff] [blame] | 1643 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 1644 | return wake_vec; |
| 1645 | } |
| 1646 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 1647 | __weak int acpi_get_gpe(int gpe) |
Duncan Laurie | 1f6e681 | 2016-09-19 12:04:19 -0700 | [diff] [blame] | 1648 | { |
| 1649 | return -1; /* implemented by SOC */ |
| 1650 | } |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1651 | |
Elyes Haouas | 8b950f4 | 2022-02-16 12:08:16 +0100 | [diff] [blame] | 1652 | u8 get_acpi_fadt_minor_version(void) |
| 1653 | { |
| 1654 | return ACPI_FADT_MINOR_VERSION_0; |
| 1655 | } |
| 1656 | |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1657 | int get_acpi_table_revision(enum acpi_tables table) |
| 1658 | { |
| 1659 | switch (table) { |
| 1660 | case FADT: |
Elyes Haouas | 8b950f4 | 2022-02-16 12:08:16 +0100 | [diff] [blame] | 1661 | return ACPI_FADT_REV_ACPI_6; |
Elyes HAOUAS | f288b39 | 2018-11-11 15:22:30 +0100 | [diff] [blame] | 1662 | 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] | 1663 | return 3; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1664 | case MCFG: |
| 1665 | return 1; |
| 1666 | case TCPA: |
| 1667 | return 2; |
Philipp Deppenwiese | 296164e0 | 2018-10-18 15:39:34 +0200 | [diff] [blame] | 1668 | case TPM2: |
| 1669 | return 4; |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1670 | case SSDT: /* ACPI 3.0 up to 6.3: 2 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1671 | return 2; |
Jonathan Zhang | a3311b9 | 2022-12-01 17:13:41 -0800 | [diff] [blame] | 1672 | case SRAT: /* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 up to 6.4: 3 */ |
| 1673 | return 3; |
Jonathan Zhang | 2a4e1f4 | 2021-04-01 11:43:37 -0700 | [diff] [blame] | 1674 | case HMAT: /* ACPI 6.4: 2 */ |
| 1675 | return 2; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1676 | case DMAR: |
| 1677 | return 1; |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1678 | case SLIT: /* ACPI 2.0 up to 6.3: 1 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1679 | return 1; |
Patrick Rudolph | 9d98e5a | 2019-06-14 19:00:04 +0200 | [diff] [blame] | 1680 | case SPMI: /* IMPI 2.0 */ |
| 1681 | return 5; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1682 | case HPET: /* Currently 1. Table added in ACPI 2.0. */ |
| 1683 | return 1; |
Elyes HAOUAS | f288b39 | 2018-11-11 15:22:30 +0100 | [diff] [blame] | 1684 | case VFCT: /* ACPI 2.0/3.0/4.0: 1 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1685 | return 1; |
| 1686 | case IVRS: |
Jason Glenesk | 1916f89 | 2020-07-24 02:51:30 -0700 | [diff] [blame] | 1687 | return IVRS_FORMAT_MIXED; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1688 | case DBG2: |
| 1689 | return 0; |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1690 | 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] | 1691 | return 1; |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1692 | case RSDT: /* ACPI 1.0 up to 6.3: 1 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1693 | return 1; |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1694 | case XSDT: /* ACPI 2.0 up to 6.3: 1 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1695 | return 1; |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 1696 | case RSDP: /* ACPI 2.0 up to 6.3: 2 */ |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1697 | return 2; |
Rocky Phagura | eff0713 | 2021-01-10 15:42:50 -0800 | [diff] [blame] | 1698 | case EINJ: |
| 1699 | return 1; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1700 | case HEST: |
| 1701 | return 1; |
| 1702 | case NHLT: |
| 1703 | return 5; |
Marshall Dawson | 44705c6 | 2018-09-04 13:47:15 -0600 | [diff] [blame] | 1704 | case BERT: |
| 1705 | return 1; |
Jonathan Zhang | a3311b9 | 2022-12-01 17:13:41 -0800 | [diff] [blame] | 1706 | case CEDT: /* CXL 3.0 section 9.17.1 */ |
| 1707 | return 1; |
Jason Glenesk | 61624b2 | 2020-11-02 20:06:23 -0800 | [diff] [blame] | 1708 | case CRAT: |
| 1709 | return 1; |
Michael Niewöhner | f0a44ae | 2021-01-01 21:04:09 +0100 | [diff] [blame] | 1710 | case LPIT: /* ACPI 5.1 up to 6.3: 0 */ |
| 1711 | return 0; |
Arthur Heymans | 9046407 | 2023-06-07 12:53:50 +0200 | [diff] [blame] | 1712 | case SPCR: |
| 1713 | return 4; |
Arthur Heymans | 2e3cb63 | 2023-06-30 15:01:08 +0200 | [diff] [blame] | 1714 | case GTDT: |
| 1715 | return 3; |
Marc Jones | 93a5176 | 2018-08-22 18:57:24 -0600 | [diff] [blame] | 1716 | default: |
| 1717 | return -1; |
| 1718 | } |
| 1719 | return -1; |
| 1720 | } |