Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Based on acpi.c from coreboot |
| 4 | * |
| 5 | * Copyright (C) 2015, Saket Sinha <saket.sinha89@gmail.com> |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 6 | * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 7 | */ |
| 8 | |
Simon Glass | 2326a8b | 2020-09-22 12:45:34 -0600 | [diff] [blame] | 9 | #define LOG_CATEGORY LOGC_ACPI |
| 10 | |
Simon Glass | 272a703 | 2020-09-22 12:45:32 -0600 | [diff] [blame] | 11 | #include <bloblist.h> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 12 | #include <cpu.h> |
| 13 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 14 | #include <log.h> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 15 | #include <dm/uclass-internal.h> |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 16 | #include <mapmem.h> |
Andy Shevchenko | 4ca48c9 | 2018-11-20 23:52:38 +0200 | [diff] [blame] | 17 | #include <serial.h> |
Simon Glass | f0a8d68 | 2020-07-07 13:12:07 -0600 | [diff] [blame] | 18 | #include <acpi/acpigen.h> |
Simon Glass | 9597189 | 2020-09-22 12:45:10 -0600 | [diff] [blame] | 19 | #include <acpi/acpi_device.h> |
Simon Glass | 858fed1 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 20 | #include <acpi/acpi_table.h> |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 21 | #include <asm/acpi/global_nvs.h> |
Andy Shevchenko | 13a5d87 | 2017-07-21 22:32:04 +0300 | [diff] [blame] | 22 | #include <asm/ioapic.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 23 | #include <asm/global_data.h> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 24 | #include <asm/lapic.h> |
Andy Shevchenko | 13a5d87 | 2017-07-21 22:32:04 +0300 | [diff] [blame] | 25 | #include <asm/mpspec.h> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 26 | #include <asm/tables.h> |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 27 | #include <asm/arch/global_nvs.h> |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 28 | #include <dm/acpi.h> |
Simon Glass | 9ed41e7 | 2020-07-07 21:32:05 -0600 | [diff] [blame] | 29 | #include <linux/err.h> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 30 | |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 31 | static int acpi_create_madt_lapic(struct acpi_madt_lapic *lapic, |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 32 | u8 cpu, u8 apic) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 33 | { |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 34 | lapic->type = ACPI_APIC_LAPIC; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 35 | lapic->length = sizeof(struct acpi_madt_lapic); |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 36 | lapic->flags = LOCAL_APIC_FLAG_ENABLED; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 37 | lapic->processor_id = cpu; |
| 38 | lapic->apic_id = apic; |
| 39 | |
| 40 | return lapic->length; |
| 41 | } |
| 42 | |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame^] | 43 | int acpi_create_madt_lapics(void *current) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 44 | { |
| 45 | struct udevice *dev; |
George McCollister | 5a49f87 | 2016-06-07 13:40:18 -0500 | [diff] [blame] | 46 | int total_length = 0; |
Simon Glass | fcae547 | 2020-09-22 12:45:31 -0600 | [diff] [blame] | 47 | int cpu_num = 0; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 48 | |
| 49 | for (uclass_find_first_device(UCLASS_CPU, &dev); |
| 50 | dev; |
| 51 | uclass_find_next_device(&dev)) { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 52 | struct cpu_plat *plat = dev_get_parent_plat(dev); |
Simon Glass | fcae547 | 2020-09-22 12:45:31 -0600 | [diff] [blame] | 53 | int length; |
| 54 | |
| 55 | length = acpi_create_madt_lapic( |
| 56 | (struct acpi_madt_lapic *)current, cpu_num++, |
| 57 | plat->cpu_id); |
Bin Meng | 3c5234e | 2016-05-07 07:46:30 -0700 | [diff] [blame] | 58 | current += length; |
George McCollister | 5a49f87 | 2016-06-07 13:40:18 -0500 | [diff] [blame] | 59 | total_length += length; |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 60 | } |
| 61 | |
George McCollister | 5a49f87 | 2016-06-07 13:40:18 -0500 | [diff] [blame] | 62 | return total_length; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 63 | } |
| 64 | |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 65 | int acpi_create_madt_ioapic(struct acpi_madt_ioapic *ioapic, u8 id, |
| 66 | u32 addr, u32 gsi_base) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 67 | { |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 68 | ioapic->type = ACPI_APIC_IOAPIC; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 69 | ioapic->length = sizeof(struct acpi_madt_ioapic); |
| 70 | ioapic->reserved = 0x00; |
| 71 | ioapic->gsi_base = gsi_base; |
| 72 | ioapic->ioapic_id = id; |
| 73 | ioapic->ioapic_addr = addr; |
| 74 | |
| 75 | return ioapic->length; |
| 76 | } |
| 77 | |
| 78 | int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride, |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 79 | u8 bus, u8 source, u32 gsirq, u16 flags) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 80 | { |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 81 | irqoverride->type = ACPI_APIC_IRQ_SRC_OVERRIDE; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 82 | irqoverride->length = sizeof(struct acpi_madt_irqoverride); |
| 83 | irqoverride->bus = bus; |
| 84 | irqoverride->source = source; |
| 85 | irqoverride->gsirq = gsirq; |
| 86 | irqoverride->flags = flags; |
| 87 | |
| 88 | return irqoverride->length; |
| 89 | } |
| 90 | |
| 91 | int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi, |
Bin Meng | 44256b0 | 2016-05-07 07:46:25 -0700 | [diff] [blame] | 92 | u8 cpu, u16 flags, u8 lint) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 93 | { |
Bin Meng | 6a42158 | 2016-05-07 07:46:21 -0700 | [diff] [blame] | 94 | lapic_nmi->type = ACPI_APIC_LAPIC_NMI; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 95 | lapic_nmi->length = sizeof(struct acpi_madt_lapic_nmi); |
| 96 | lapic_nmi->flags = flags; |
| 97 | lapic_nmi->processor_id = cpu; |
| 98 | lapic_nmi->lint = lint; |
| 99 | |
| 100 | return lapic_nmi->length; |
| 101 | } |
| 102 | |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame^] | 103 | static int acpi_create_madt_irq_overrides(void *current) |
Andy Shevchenko | 13a5d87 | 2017-07-21 22:32:04 +0300 | [diff] [blame] | 104 | { |
| 105 | struct acpi_madt_irqoverride *irqovr; |
| 106 | u16 sci_flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH; |
| 107 | int length = 0; |
| 108 | |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame^] | 109 | irqovr = current; |
Andy Shevchenko | 13a5d87 | 2017-07-21 22:32:04 +0300 | [diff] [blame] | 110 | length += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0); |
| 111 | |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame^] | 112 | irqovr = current + length; |
Andy Shevchenko | 13a5d87 | 2017-07-21 22:32:04 +0300 | [diff] [blame] | 113 | length += acpi_create_madt_irqoverride(irqovr, 0, 9, 9, sci_flags); |
| 114 | |
| 115 | return length; |
| 116 | } |
| 117 | |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame^] | 118 | __weak void *acpi_fill_madt(struct acpi_madt *madt, struct acpi_ctx *ctx) |
Andy Shevchenko | 13a5d87 | 2017-07-21 22:32:04 +0300 | [diff] [blame] | 119 | { |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame^] | 120 | void *current = ctx->current; |
| 121 | |
| 122 | madt->lapic_addr = LAPIC_DEFAULT_BASE; |
| 123 | madt->flags = ACPI_MADT_PCAT_COMPAT; |
| 124 | |
Andy Shevchenko | 13a5d87 | 2017-07-21 22:32:04 +0300 | [diff] [blame] | 125 | current += acpi_create_madt_lapics(current); |
| 126 | |
| 127 | current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current, |
| 128 | io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0); |
| 129 | |
| 130 | current += acpi_create_madt_irq_overrides(current); |
| 131 | |
| 132 | return current; |
| 133 | } |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 134 | |
Simon Glass | 2802628 | 2020-09-22 12:45:33 -0600 | [diff] [blame] | 135 | /** |
| 136 | * acpi_create_tcpa() - Create a TCPA table |
| 137 | * |
Simon Glass | 2802628 | 2020-09-22 12:45:33 -0600 | [diff] [blame] | 138 | * Trusted Computing Platform Alliance Capabilities Table |
| 139 | * TCPA PC Specific Implementation SpecificationTCPA is defined in the PCI |
| 140 | * Firmware Specification 3.0 |
| 141 | */ |
Simon Glass | bb3b608 | 2021-12-01 09:02:59 -0700 | [diff] [blame] | 142 | int acpi_write_tcpa(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
Simon Glass | 2802628 | 2020-09-22 12:45:33 -0600 | [diff] [blame] | 143 | { |
Simon Glass | bb3b608 | 2021-12-01 09:02:59 -0700 | [diff] [blame] | 144 | struct acpi_table_header *header; |
| 145 | struct acpi_tcpa *tcpa; |
| 146 | u32 current; |
Simon Glass | 2802628 | 2020-09-22 12:45:33 -0600 | [diff] [blame] | 147 | int size = 0x10000; /* Use this as the default size */ |
| 148 | void *log; |
| 149 | int ret; |
| 150 | |
Simon Glass | bb3b608 | 2021-12-01 09:02:59 -0700 | [diff] [blame] | 151 | if (!IS_ENABLED(CONFIG_TPM_V1)) |
| 152 | return -ENOENT; |
Simon Glass | 2802628 | 2020-09-22 12:45:33 -0600 | [diff] [blame] | 153 | if (!CONFIG_IS_ENABLED(BLOBLIST)) |
| 154 | return -ENXIO; |
Simon Glass | bb3b608 | 2021-12-01 09:02:59 -0700 | [diff] [blame] | 155 | |
| 156 | tcpa = ctx->current; |
| 157 | header = &tcpa->header; |
Simon Glass | 2802628 | 2020-09-22 12:45:33 -0600 | [diff] [blame] | 158 | memset(tcpa, '\0', sizeof(struct acpi_tcpa)); |
| 159 | |
| 160 | /* Fill out header fields */ |
| 161 | acpi_fill_header(header, "TCPA"); |
| 162 | header->length = sizeof(struct acpi_tcpa); |
| 163 | header->revision = 1; |
| 164 | |
| 165 | ret = bloblist_ensure_size_ret(BLOBLISTT_TCPA_LOG, &size, &log); |
| 166 | if (ret) |
| 167 | return log_msg_ret("blob", ret); |
| 168 | |
| 169 | tcpa->platform_class = 0; |
| 170 | tcpa->laml = size; |
Simon Glass | 919f835 | 2023-12-31 08:25:54 -0700 | [diff] [blame] | 171 | tcpa->lasa = nomap_to_sysmem(log); |
Simon Glass | 2802628 | 2020-09-22 12:45:33 -0600 | [diff] [blame] | 172 | |
| 173 | /* (Re)calculate length and checksum */ |
Simon Glass | bb3b608 | 2021-12-01 09:02:59 -0700 | [diff] [blame] | 174 | current = (u32)tcpa + sizeof(struct acpi_tcpa); |
Simon Glass | 2802628 | 2020-09-22 12:45:33 -0600 | [diff] [blame] | 175 | header->length = current - (u32)tcpa; |
Simon Glass | bb3b608 | 2021-12-01 09:02:59 -0700 | [diff] [blame] | 176 | header->checksum = table_compute_checksum(tcpa, header->length); |
| 177 | |
| 178 | acpi_inc(ctx, tcpa->header.length); |
| 179 | acpi_add_table(ctx, tcpa); |
Simon Glass | 2802628 | 2020-09-22 12:45:33 -0600 | [diff] [blame] | 180 | |
| 181 | return 0; |
| 182 | } |
Simon Glass | bb3b608 | 2021-12-01 09:02:59 -0700 | [diff] [blame] | 183 | ACPI_WRITER(5tcpa, "TCPA", acpi_write_tcpa, 0); |
Simon Glass | 2802628 | 2020-09-22 12:45:33 -0600 | [diff] [blame] | 184 | |
Simon Glass | 272a703 | 2020-09-22 12:45:32 -0600 | [diff] [blame] | 185 | static int get_tpm2_log(void **ptrp, int *sizep) |
| 186 | { |
| 187 | const int tpm2_default_log_len = 0x10000; |
| 188 | int size; |
| 189 | int ret; |
| 190 | |
| 191 | *sizep = 0; |
| 192 | size = tpm2_default_log_len; |
| 193 | ret = bloblist_ensure_size_ret(BLOBLISTT_TPM2_TCG_LOG, &size, ptrp); |
| 194 | if (ret) |
| 195 | return log_msg_ret("blob", ret); |
| 196 | *sizep = size; |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
Simon Glass | c753694 | 2021-12-01 09:02:57 -0700 | [diff] [blame] | 201 | static int acpi_write_tpm2(struct acpi_ctx *ctx, |
| 202 | const struct acpi_writer *entry) |
Simon Glass | 272a703 | 2020-09-22 12:45:32 -0600 | [diff] [blame] | 203 | { |
Simon Glass | c753694 | 2021-12-01 09:02:57 -0700 | [diff] [blame] | 204 | struct acpi_table_header *header; |
| 205 | struct acpi_tpm2 *tpm2; |
Simon Glass | 272a703 | 2020-09-22 12:45:32 -0600 | [diff] [blame] | 206 | int tpm2_log_len; |
| 207 | void *lasa; |
| 208 | int ret; |
| 209 | |
Simon Glass | c753694 | 2021-12-01 09:02:57 -0700 | [diff] [blame] | 210 | if (!IS_ENABLED(CONFIG_TPM_V2)) |
| 211 | return log_msg_ret("none", -ENOENT); |
| 212 | |
| 213 | tpm2 = ctx->current; |
| 214 | header = &tpm2->header; |
| 215 | memset(tpm2, '\0', sizeof(struct acpi_tpm2)); |
Simon Glass | 272a703 | 2020-09-22 12:45:32 -0600 | [diff] [blame] | 216 | |
| 217 | /* |
| 218 | * Some payloads like SeaBIOS depend on log area to use TPM2. |
| 219 | * Get the memory size and address of TPM2 log area or initialize it. |
| 220 | */ |
| 221 | ret = get_tpm2_log(&lasa, &tpm2_log_len); |
| 222 | if (ret) |
Simon Glass | c753694 | 2021-12-01 09:02:57 -0700 | [diff] [blame] | 223 | return log_msg_ret("log", ret); |
Simon Glass | 272a703 | 2020-09-22 12:45:32 -0600 | [diff] [blame] | 224 | |
| 225 | /* Fill out header fields. */ |
| 226 | acpi_fill_header(header, "TPM2"); |
Heinrich Schuchardt | 10de8a8 | 2024-01-21 12:52:48 +0100 | [diff] [blame] | 227 | memcpy(header->creator_id, ASLC_ID, 4); |
Simon Glass | 272a703 | 2020-09-22 12:45:32 -0600 | [diff] [blame] | 228 | |
| 229 | header->length = sizeof(struct acpi_tpm2); |
| 230 | header->revision = acpi_get_table_revision(ACPITAB_TPM2); |
| 231 | |
Simon Glass | c753694 | 2021-12-01 09:02:57 -0700 | [diff] [blame] | 232 | /* Hard to detect for U-Boot. Just set it to 0 */ |
Simon Glass | 272a703 | 2020-09-22 12:45:32 -0600 | [diff] [blame] | 233 | tpm2->platform_class = 0; |
| 234 | |
| 235 | /* Must be set to 0 for FIFO-interface support */ |
| 236 | tpm2->control_area = 0; |
| 237 | tpm2->start_method = 6; |
| 238 | memset(tpm2->msp, 0, sizeof(tpm2->msp)); |
| 239 | |
| 240 | /* Fill the log area size and start address fields. */ |
| 241 | tpm2->laml = tpm2_log_len; |
Simon Glass | 919f835 | 2023-12-31 08:25:54 -0700 | [diff] [blame] | 242 | tpm2->lasa = nomap_to_sysmem(lasa); |
Simon Glass | 272a703 | 2020-09-22 12:45:32 -0600 | [diff] [blame] | 243 | |
| 244 | /* Calculate checksum. */ |
Simon Glass | c753694 | 2021-12-01 09:02:57 -0700 | [diff] [blame] | 245 | header->checksum = table_compute_checksum(tpm2, header->length); |
| 246 | |
| 247 | acpi_inc(ctx, tpm2->header.length); |
| 248 | acpi_add_table(ctx, tpm2); |
Simon Glass | 272a703 | 2020-09-22 12:45:32 -0600 | [diff] [blame] | 249 | |
| 250 | return 0; |
| 251 | } |
Simon Glass | c753694 | 2021-12-01 09:02:57 -0700 | [diff] [blame] | 252 | ACPI_WRITER(5tpm2, "TPM2", acpi_write_tpm2, 0); |
Simon Glass | 272a703 | 2020-09-22 12:45:32 -0600 | [diff] [blame] | 253 | |
Simon Glass | d2a98eb | 2021-12-01 09:02:53 -0700 | [diff] [blame] | 254 | int acpi_write_gnvs(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 255 | { |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 256 | ulong addr; |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 257 | |
Simon Glass | 6fe570a | 2020-09-22 12:44:53 -0600 | [diff] [blame] | 258 | if (!IS_ENABLED(CONFIG_ACPI_GNVS_EXTERNAL)) { |
Simon Glass | d2a98eb | 2021-12-01 09:02:53 -0700 | [diff] [blame] | 259 | int i; |
| 260 | |
| 261 | /* We need the DSDT to be done */ |
| 262 | if (!ctx->dsdt) |
| 263 | return log_msg_ret("dsdt", -EAGAIN); |
| 264 | |
Simon Glass | 6fe570a | 2020-09-22 12:44:53 -0600 | [diff] [blame] | 265 | /* Pack GNVS into the ACPI table area */ |
Simon Glass | 83c3cb5 | 2021-12-01 09:02:52 -0700 | [diff] [blame] | 266 | for (i = 0; i < ctx->dsdt->length; i++) { |
| 267 | u32 *gnvs = (u32 *)((u32)ctx->dsdt + i); |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 268 | |
Simon Glass | 6fe570a | 2020-09-22 12:44:53 -0600 | [diff] [blame] | 269 | if (*gnvs == ACPI_GNVS_ADDR) { |
Simon Glass | 919f835 | 2023-12-31 08:25:54 -0700 | [diff] [blame] | 270 | *gnvs = nomap_to_sysmem(ctx->current); |
Simon Glass | d2a98eb | 2021-12-01 09:02:53 -0700 | [diff] [blame] | 271 | log_debug("Fix up global NVS in DSDT to %#08x\n", |
| 272 | *gnvs); |
Simon Glass | 6fe570a | 2020-09-22 12:44:53 -0600 | [diff] [blame] | 273 | break; |
| 274 | } |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 275 | } |
Simon Glass | 6fe570a | 2020-09-22 12:44:53 -0600 | [diff] [blame] | 276 | |
| 277 | /* |
Simon Glass | d2a98eb | 2021-12-01 09:02:53 -0700 | [diff] [blame] | 278 | * Recalculate the length and update the DSDT checksum since we |
| 279 | * patched the GNVS address. Set the checksum to zero since it |
| 280 | * is part of the region being checksummed. |
Simon Glass | 6fe570a | 2020-09-22 12:44:53 -0600 | [diff] [blame] | 281 | */ |
Simon Glass | d2a98eb | 2021-12-01 09:02:53 -0700 | [diff] [blame] | 282 | ctx->dsdt->checksum = 0; |
| 283 | ctx->dsdt->checksum = table_compute_checksum((void *)ctx->dsdt, |
| 284 | ctx->dsdt->length); |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Simon Glass | d2a98eb | 2021-12-01 09:02:53 -0700 | [diff] [blame] | 287 | /* Fill in platform-specific global NVS variables */ |
Simon Glass | 9ed41e7 | 2020-07-07 21:32:05 -0600 | [diff] [blame] | 288 | addr = acpi_create_gnvs(ctx->current); |
| 289 | if (IS_ERR_VALUE(addr)) |
Simon Glass | d2a98eb | 2021-12-01 09:02:53 -0700 | [diff] [blame] | 290 | return log_msg_ret("gnvs", (int)addr); |
Simon Glass | 9ed41e7 | 2020-07-07 21:32:05 -0600 | [diff] [blame] | 291 | |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 292 | acpi_inc_align(ctx, sizeof(struct acpi_global_nvs)); |
Bin Meng | d9050c6 | 2016-06-17 02:13:16 -0700 | [diff] [blame] | 293 | |
Simon Glass | d2a98eb | 2021-12-01 09:02:53 -0700 | [diff] [blame] | 294 | return 0; |
| 295 | } |
| 296 | ACPI_WRITER(4gnvs, "GNVS", acpi_write_gnvs, 0); |
| 297 | |
Simon Glass | 4ffe8b0 | 2020-09-22 12:45:09 -0600 | [diff] [blame] | 298 | /** |
| 299 | * acpi_write_hpet() - Write out a HPET table |
| 300 | * |
| 301 | * Write out the table for High-Precision Event Timers |
| 302 | * |
| 303 | * @hpet: Place to put HPET table |
| 304 | */ |
| 305 | static int acpi_create_hpet(struct acpi_hpet *hpet) |
| 306 | { |
| 307 | struct acpi_table_header *header = &hpet->header; |
| 308 | struct acpi_gen_regaddr *addr = &hpet->addr; |
| 309 | |
| 310 | /* |
| 311 | * See IA-PC HPET (High Precision Event Timers) Specification v1.0a |
| 312 | * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/software-developers-hpet-spec-1-0a.pdf |
| 313 | */ |
| 314 | memset((void *)hpet, '\0', sizeof(struct acpi_hpet)); |
| 315 | |
| 316 | /* Fill out header fields. */ |
| 317 | acpi_fill_header(header, "HPET"); |
| 318 | |
Simon Glass | 4ffe8b0 | 2020-09-22 12:45:09 -0600 | [diff] [blame] | 319 | header->length = sizeof(struct acpi_hpet); |
| 320 | header->revision = acpi_get_table_revision(ACPITAB_HPET); |
| 321 | |
| 322 | /* Fill out HPET address */ |
| 323 | addr->space_id = 0; /* Memory */ |
| 324 | addr->bit_width = 64; |
| 325 | addr->bit_offset = 0; |
| 326 | addr->addrl = CONFIG_HPET_ADDRESS & 0xffffffff; |
| 327 | addr->addrh = ((unsigned long long)CONFIG_HPET_ADDRESS) >> 32; |
| 328 | |
| 329 | hpet->id = *(u32 *)CONFIG_HPET_ADDRESS; |
| 330 | hpet->number = 0; |
| 331 | hpet->min_tick = 0; /* HPET_MIN_TICKS */ |
| 332 | |
| 333 | header->checksum = table_compute_checksum(hpet, |
| 334 | sizeof(struct acpi_hpet)); |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | int acpi_write_hpet(struct acpi_ctx *ctx) |
| 340 | { |
| 341 | struct acpi_hpet *hpet; |
| 342 | int ret; |
| 343 | |
| 344 | log_debug("ACPI: * HPET\n"); |
| 345 | |
| 346 | hpet = ctx->current; |
| 347 | acpi_inc_align(ctx, sizeof(struct acpi_hpet)); |
| 348 | acpi_create_hpet(hpet); |
| 349 | ret = acpi_add_table(ctx, hpet); |
| 350 | if (ret) |
| 351 | return log_msg_ret("add", ret); |
| 352 | |
| 353 | return 0; |
| 354 | } |
Simon Glass | 9597189 | 2020-09-22 12:45:10 -0600 | [diff] [blame] | 355 | |
Simon Glass | 87cf8d2 | 2020-09-22 12:45:16 -0600 | [diff] [blame] | 356 | void acpi_create_dmar_drhd(struct acpi_ctx *ctx, uint flags, uint segment, |
| 357 | u64 bar) |
| 358 | { |
| 359 | struct dmar_entry *drhd = ctx->current; |
| 360 | |
| 361 | memset(drhd, '\0', sizeof(*drhd)); |
| 362 | drhd->type = DMAR_DRHD; |
| 363 | drhd->length = sizeof(*drhd); /* will be fixed up later */ |
| 364 | drhd->flags = flags; |
| 365 | drhd->segment = segment; |
| 366 | drhd->bar = bar; |
| 367 | acpi_inc(ctx, drhd->length); |
| 368 | } |
| 369 | |
| 370 | void acpi_create_dmar_rmrr(struct acpi_ctx *ctx, uint segment, u64 bar, |
| 371 | u64 limit) |
| 372 | { |
| 373 | struct dmar_rmrr_entry *rmrr = ctx->current; |
| 374 | |
| 375 | memset(rmrr, '\0', sizeof(*rmrr)); |
| 376 | rmrr->type = DMAR_RMRR; |
| 377 | rmrr->length = sizeof(*rmrr); /* will be fixed up later */ |
| 378 | rmrr->segment = segment; |
| 379 | rmrr->bar = bar; |
| 380 | rmrr->limit = limit; |
| 381 | acpi_inc(ctx, rmrr->length); |
| 382 | } |
| 383 | |
| 384 | void acpi_dmar_drhd_fixup(struct acpi_ctx *ctx, void *base) |
| 385 | { |
| 386 | struct dmar_entry *drhd = base; |
| 387 | |
| 388 | drhd->length = ctx->current - base; |
| 389 | } |
| 390 | |
| 391 | void acpi_dmar_rmrr_fixup(struct acpi_ctx *ctx, void *base) |
| 392 | { |
| 393 | struct dmar_rmrr_entry *rmrr = base; |
| 394 | |
| 395 | rmrr->length = ctx->current - base; |
| 396 | } |
| 397 | |
| 398 | static int acpi_create_dmar_ds(struct acpi_ctx *ctx, enum dev_scope_type type, |
| 399 | uint enumeration_id, pci_dev_t bdf) |
| 400 | { |
| 401 | /* we don't support longer paths yet */ |
| 402 | const size_t dev_scope_length = sizeof(struct dev_scope) + 2; |
| 403 | struct dev_scope *ds = ctx->current; |
| 404 | |
| 405 | memset(ds, '\0', dev_scope_length); |
| 406 | ds->type = type; |
| 407 | ds->length = dev_scope_length; |
| 408 | ds->enumeration = enumeration_id; |
| 409 | ds->start_bus = PCI_BUS(bdf); |
| 410 | ds->path[0].dev = PCI_DEV(bdf); |
| 411 | ds->path[0].fn = PCI_FUNC(bdf); |
| 412 | |
| 413 | return ds->length; |
| 414 | } |
| 415 | |
| 416 | int acpi_create_dmar_ds_pci_br(struct acpi_ctx *ctx, pci_dev_t bdf) |
| 417 | { |
| 418 | return acpi_create_dmar_ds(ctx, SCOPE_PCI_SUB, 0, bdf); |
| 419 | } |
| 420 | |
| 421 | int acpi_create_dmar_ds_pci(struct acpi_ctx *ctx, pci_dev_t bdf) |
| 422 | { |
| 423 | return acpi_create_dmar_ds(ctx, SCOPE_PCI_ENDPOINT, 0, bdf); |
| 424 | } |
| 425 | |
| 426 | int acpi_create_dmar_ds_ioapic(struct acpi_ctx *ctx, uint enumeration_id, |
| 427 | pci_dev_t bdf) |
| 428 | { |
| 429 | return acpi_create_dmar_ds(ctx, SCOPE_IOAPIC, enumeration_id, bdf); |
| 430 | } |
| 431 | |
| 432 | int acpi_create_dmar_ds_msi_hpet(struct acpi_ctx *ctx, uint enumeration_id, |
| 433 | pci_dev_t bdf) |
| 434 | { |
| 435 | return acpi_create_dmar_ds(ctx, SCOPE_MSI_HPET, enumeration_id, bdf); |
| 436 | } |