Simon Glass | b2672ea | 2020-04-08 16:57:38 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Generic code used to generate ACPI tables |
| 4 | * |
| 5 | * Copyright 2019 Google LLC |
| 6 | */ |
| 7 | |
Patrick Rudolph | 158efd6 | 2024-10-23 15:19:57 +0200 | [diff] [blame] | 8 | #include <bloblist.h> |
Simon Glass | e962989 | 2020-04-08 16:57:39 -0600 | [diff] [blame] | 9 | #include <cpu.h> |
Patrick Rudolph | 158efd6 | 2024-10-23 15:19:57 +0200 | [diff] [blame] | 10 | #include <dm.h> |
| 11 | #include <efi_api.h> |
| 12 | #include <efi_loader.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 14 | #include <mapmem.h> |
| 15 | #include <tables_csum.h> |
Maximilian Brune | d7fa54b | 2024-10-23 15:19:44 +0200 | [diff] [blame] | 16 | #include <serial.h> |
Simon Glass | 90b0127 | 2023-04-29 19:21:46 -0600 | [diff] [blame] | 17 | #include <version_string.h> |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 18 | #include <acpi/acpi_table.h> |
Maximilian Brune | d7fa54b | 2024-10-23 15:19:44 +0200 | [diff] [blame] | 19 | #include <acpi/acpi_device.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 21 | #include <dm/acpi.h> |
Patrick Rudolph | 158efd6 | 2024-10-23 15:19:57 +0200 | [diff] [blame] | 22 | #include <linux/sizes.h> |
| 23 | #include <linux/log2.h> |
| 24 | |
| 25 | enum { |
| 26 | TABLE_SIZE = SZ_64K, |
| 27 | }; |
| 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
Simon Glass | e962989 | 2020-04-08 16:57:39 -0600 | [diff] [blame] | 30 | |
Pali Rohár | f0de20e | 2021-07-10 13:10:01 +0200 | [diff] [blame] | 31 | /* |
| 32 | * OEM_REVISION is 32-bit unsigned number. It should be increased only when |
| 33 | * changing software version. Therefore it should not depend on build time. |
| 34 | * U-Boot calculates it from U-Boot version and represent it in hexadecimal |
| 35 | * notation. As U-Boot version is in form year.month set low 8 bits to 0x01 |
| 36 | * to have valid date. So for U-Boot version 2021.04 OEM_REVISION is set to |
| 37 | * value 0x20210401. |
| 38 | */ |
Simon Glass | 90b0127 | 2023-04-29 19:21:46 -0600 | [diff] [blame] | 39 | #define OEM_REVISION ((((version_num / 1000) % 10) << 28) | \ |
| 40 | (((version_num / 100) % 10) << 24) | \ |
| 41 | (((version_num / 10) % 10) << 20) | \ |
| 42 | ((version_num % 10) << 16) | \ |
| 43 | (((version_num_patch / 10) % 10) << 12) | \ |
| 44 | ((version_num_patch % 10) << 8) | \ |
Pali Rohár | f0de20e | 2021-07-10 13:10:01 +0200 | [diff] [blame] | 45 | 0x01) |
| 46 | |
Simon Glass | e962989 | 2020-04-08 16:57:39 -0600 | [diff] [blame] | 47 | int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags) |
| 48 | { |
| 49 | struct acpi_table_header *header = &dmar->header; |
| 50 | struct cpu_info info; |
| 51 | struct udevice *cpu; |
| 52 | int ret; |
| 53 | |
Michal Suchanek | ac12a2f | 2022-10-12 21:57:59 +0200 | [diff] [blame] | 54 | ret = uclass_first_device_err(UCLASS_CPU, &cpu); |
Simon Glass | e962989 | 2020-04-08 16:57:39 -0600 | [diff] [blame] | 55 | if (ret) |
| 56 | return log_msg_ret("cpu", ret); |
| 57 | ret = cpu_get_info(cpu, &info); |
| 58 | if (ret) |
| 59 | return log_msg_ret("info", ret); |
| 60 | memset((void *)dmar, 0, sizeof(struct acpi_dmar)); |
| 61 | |
| 62 | /* Fill out header fields. */ |
| 63 | acpi_fill_header(&dmar->header, "DMAR"); |
| 64 | header->length = sizeof(struct acpi_dmar); |
| 65 | header->revision = acpi_get_table_revision(ACPITAB_DMAR); |
| 66 | |
| 67 | dmar->host_address_width = info.address_width - 1; |
| 68 | dmar->flags = flags; |
Simon Glass | 7b9e8f4 | 2025-03-15 14:26:03 +0000 | [diff] [blame] | 69 | header->checksum = table_compute_checksum(dmar, header->length); |
Simon Glass | e962989 | 2020-04-08 16:57:39 -0600 | [diff] [blame] | 70 | |
| 71 | return 0; |
| 72 | } |
Simon Glass | b2672ea | 2020-04-08 16:57:38 -0600 | [diff] [blame] | 73 | |
| 74 | int acpi_get_table_revision(enum acpi_tables table) |
| 75 | { |
| 76 | switch (table) { |
| 77 | case ACPITAB_FADT: |
Patrick Rudolph | f317fce | 2024-10-23 15:19:52 +0200 | [diff] [blame] | 78 | return ACPI_FADT_REV_ACPI_6_0; |
Simon Glass | b2672ea | 2020-04-08 16:57:38 -0600 | [diff] [blame] | 79 | case ACPITAB_MADT: |
Patrick Rudolph | f317fce | 2024-10-23 15:19:52 +0200 | [diff] [blame] | 80 | return ACPI_MADT_REV_ACPI_6_2; |
Simon Glass | b2672ea | 2020-04-08 16:57:38 -0600 | [diff] [blame] | 81 | case ACPITAB_MCFG: |
| 82 | return ACPI_MCFG_REV_ACPI_3_0; |
| 83 | case ACPITAB_TCPA: |
| 84 | /* This version and the rest are open-coded */ |
| 85 | return 2; |
| 86 | case ACPITAB_TPM2: |
| 87 | return 4; |
| 88 | case ACPITAB_SSDT: /* ACPI 3.0 upto 6.3: 2 */ |
| 89 | return 2; |
| 90 | case ACPITAB_SRAT: /* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 to 6.3: 3 */ |
| 91 | return 1; /* TODO Should probably be upgraded to 2 */ |
| 92 | case ACPITAB_DMAR: |
| 93 | return 1; |
| 94 | case ACPITAB_SLIT: /* ACPI 2.0 upto 6.3: 1 */ |
| 95 | return 1; |
| 96 | case ACPITAB_SPMI: /* IMPI 2.0 */ |
| 97 | return 5; |
| 98 | case ACPITAB_HPET: /* Currently 1. Table added in ACPI 2.0 */ |
| 99 | return 1; |
| 100 | case ACPITAB_VFCT: /* ACPI 2.0/3.0/4.0: 1 */ |
| 101 | return 1; |
| 102 | case ACPITAB_IVRS: |
| 103 | return IVRS_FORMAT_FIXED; |
| 104 | case ACPITAB_DBG2: |
| 105 | return 0; |
| 106 | case ACPITAB_FACS: /* ACPI 2.0/3.0: 1, ACPI 4.0 to 6.3: 2 */ |
| 107 | return 1; |
| 108 | case ACPITAB_RSDT: /* ACPI 1.0 upto 6.3: 1 */ |
| 109 | return 1; |
| 110 | case ACPITAB_XSDT: /* ACPI 2.0 upto 6.3: 1 */ |
| 111 | return 1; |
| 112 | case ACPITAB_RSDP: /* ACPI 2.0 upto 6.3: 2 */ |
| 113 | return 2; |
| 114 | case ACPITAB_HEST: |
| 115 | return 1; |
| 116 | case ACPITAB_NHLT: |
| 117 | return 5; |
| 118 | case ACPITAB_BERT: |
| 119 | return 1; |
| 120 | case ACPITAB_SPCR: |
| 121 | return 2; |
Patrick Rudolph | 4d3cf1a | 2024-10-23 15:19:53 +0200 | [diff] [blame] | 122 | case ACPITAB_PPTT: /* ACPI 6.2: 1 */ |
| 123 | return 1; |
| 124 | case ACPITAB_GTDT: /* ACPI 6.2: 2, ACPI 6.3: 3 */ |
| 125 | return 2; |
Simon Glass | b2672ea | 2020-04-08 16:57:38 -0600 | [diff] [blame] | 126 | default: |
| 127 | return -EINVAL; |
| 128 | } |
| 129 | } |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 130 | |
| 131 | void acpi_fill_header(struct acpi_table_header *header, char *signature) |
| 132 | { |
| 133 | memcpy(header->signature, signature, 4); |
| 134 | memcpy(header->oem_id, OEM_ID, 6); |
| 135 | memcpy(header->oem_table_id, OEM_TABLE_ID, 8); |
Pali Rohár | f0de20e | 2021-07-10 13:10:01 +0200 | [diff] [blame] | 136 | header->oem_revision = OEM_REVISION; |
Heinrich Schuchardt | 10de8a8 | 2024-01-21 12:52:48 +0100 | [diff] [blame] | 137 | memcpy(header->creator_id, ASLC_ID, 4); |
Heinrich Schuchardt | 9838d34 | 2024-04-18 05:11:13 +0200 | [diff] [blame] | 138 | header->creator_revision = ASL_REVISION; |
Simon Glass | 17968c3 | 2020-04-26 09:19:46 -0600 | [diff] [blame] | 139 | } |
Simon Glass | 0e11384 | 2020-04-26 09:19:47 -0600 | [diff] [blame] | 140 | |
| 141 | void acpi_align(struct acpi_ctx *ctx) |
| 142 | { |
| 143 | ctx->current = (void *)ALIGN((ulong)ctx->current, 16); |
| 144 | } |
| 145 | |
| 146 | void acpi_align64(struct acpi_ctx *ctx) |
| 147 | { |
| 148 | ctx->current = (void *)ALIGN((ulong)ctx->current, 64); |
| 149 | } |
| 150 | |
| 151 | void acpi_inc(struct acpi_ctx *ctx, uint amount) |
| 152 | { |
| 153 | ctx->current += amount; |
| 154 | } |
| 155 | |
| 156 | void acpi_inc_align(struct acpi_ctx *ctx, uint amount) |
| 157 | { |
| 158 | ctx->current += amount; |
| 159 | acpi_align(ctx); |
| 160 | } |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length |
| 164 | * and checksum. |
| 165 | */ |
| 166 | int acpi_add_table(struct acpi_ctx *ctx, void *table) |
| 167 | { |
| 168 | int i, entries_num; |
| 169 | struct acpi_rsdt *rsdt; |
| 170 | struct acpi_xsdt *xsdt; |
| 171 | |
Patrick Rudolph | d69eb29 | 2024-10-23 15:19:56 +0200 | [diff] [blame] | 172 | /* On legacy x86 platforms the RSDT is mandatory while the XSDT is not. |
| 173 | * On other platforms there might be no memory below 4GiB, thus RSDT is NULL. |
| 174 | */ |
| 175 | if (ctx->rsdt) { |
| 176 | rsdt = ctx->rsdt; |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 177 | |
Patrick Rudolph | d69eb29 | 2024-10-23 15:19:56 +0200 | [diff] [blame] | 178 | /* This should always be MAX_ACPI_TABLES */ |
| 179 | entries_num = ARRAY_SIZE(rsdt->entry); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 180 | |
Patrick Rudolph | d69eb29 | 2024-10-23 15:19:56 +0200 | [diff] [blame] | 181 | for (i = 0; i < entries_num; i++) { |
| 182 | if (rsdt->entry[i] == 0) |
| 183 | break; |
| 184 | } |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 185 | |
Patrick Rudolph | d69eb29 | 2024-10-23 15:19:56 +0200 | [diff] [blame] | 186 | if (i >= entries_num) { |
| 187 | log_err("ACPI: Error: too many tables\n"); |
| 188 | return -E2BIG; |
| 189 | } |
| 190 | |
| 191 | /* Add table to the RSDT */ |
| 192 | rsdt->entry[i] = nomap_to_sysmem(table); |
| 193 | |
| 194 | /* Fix RSDT length or the kernel will assume invalid entries */ |
| 195 | rsdt->header.length = sizeof(struct acpi_table_header) + |
| 196 | (sizeof(u32) * (i + 1)); |
| 197 | |
| 198 | /* Re-calculate checksum */ |
Heinrich Schuchardt | 7b332b5 | 2025-03-22 00:21:17 +0100 | [diff] [blame] | 199 | acpi_update_checksum(&rsdt->header); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 200 | } |
| 201 | |
Patrick Rudolph | d69eb29 | 2024-10-23 15:19:56 +0200 | [diff] [blame] | 202 | if (ctx->xsdt) { |
| 203 | /* |
| 204 | * And now the same thing for the XSDT. We use the same index as for |
| 205 | * now we want the XSDT and RSDT to always be in sync in U-Boot |
| 206 | */ |
| 207 | xsdt = ctx->xsdt; |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 208 | |
Patrick Rudolph | d69eb29 | 2024-10-23 15:19:56 +0200 | [diff] [blame] | 209 | /* This should always be MAX_ACPI_TABLES */ |
| 210 | entries_num = ARRAY_SIZE(xsdt->entry); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 211 | |
Patrick Rudolph | d69eb29 | 2024-10-23 15:19:56 +0200 | [diff] [blame] | 212 | for (i = 0; i < entries_num; i++) { |
| 213 | if (xsdt->entry[i] == 0) |
| 214 | break; |
| 215 | } |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 216 | |
Patrick Rudolph | d69eb29 | 2024-10-23 15:19:56 +0200 | [diff] [blame] | 217 | if (i >= entries_num) { |
| 218 | log_err("ACPI: Error: too many tables\n"); |
| 219 | return -E2BIG; |
| 220 | } |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 221 | |
Patrick Rudolph | d69eb29 | 2024-10-23 15:19:56 +0200 | [diff] [blame] | 222 | /* Add table to the XSDT */ |
| 223 | xsdt->entry[i] = nomap_to_sysmem(table); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 224 | |
Patrick Rudolph | d69eb29 | 2024-10-23 15:19:56 +0200 | [diff] [blame] | 225 | /* Fix XSDT length */ |
| 226 | xsdt->header.length = sizeof(struct acpi_table_header) + |
| 227 | (sizeof(u64) * (i + 1)); |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 228 | |
Patrick Rudolph | d69eb29 | 2024-10-23 15:19:56 +0200 | [diff] [blame] | 229 | /* Re-calculate checksum */ |
Heinrich Schuchardt | 7b332b5 | 2025-03-22 00:21:17 +0100 | [diff] [blame] | 230 | acpi_update_checksum(&xsdt->header); |
Patrick Rudolph | d69eb29 | 2024-10-23 15:19:56 +0200 | [diff] [blame] | 231 | } |
Simon Glass | 575a547 | 2020-04-26 09:19:50 -0600 | [diff] [blame] | 232 | |
| 233 | return 0; |
| 234 | } |
Simon Glass | 9c442a6 | 2020-04-26 09:19:51 -0600 | [diff] [blame] | 235 | |
Maximilian Brune | 8dc4512 | 2024-10-23 15:19:45 +0200 | [diff] [blame] | 236 | int acpi_write_fadt(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
| 237 | { |
| 238 | struct acpi_table_header *header; |
| 239 | struct acpi_fadt *fadt; |
| 240 | |
| 241 | fadt = ctx->current; |
| 242 | header = &fadt->header; |
| 243 | |
| 244 | memset((void *)fadt, '\0', sizeof(struct acpi_fadt)); |
| 245 | |
| 246 | acpi_fill_header(header, "FACP"); |
| 247 | header->length = sizeof(struct acpi_fadt); |
| 248 | header->revision = acpi_get_table_revision(ACPITAB_FADT); |
| 249 | memcpy(header->oem_id, OEM_ID, 6); |
| 250 | memcpy(header->oem_table_id, OEM_TABLE_ID, 8); |
| 251 | memcpy(header->creator_id, ASLC_ID, 4); |
| 252 | header->creator_revision = 1; |
Patrick Rudolph | f317fce | 2024-10-23 15:19:52 +0200 | [diff] [blame] | 253 | fadt->minor_revision = 2; |
Maximilian Brune | 8dc4512 | 2024-10-23 15:19:45 +0200 | [diff] [blame] | 254 | |
Simon Glass | 4cd81bc | 2025-03-15 14:26:02 +0000 | [diff] [blame] | 255 | fadt->x_firmware_ctrl = nomap_to_sysmem(ctx->facs); |
| 256 | fadt->x_dsdt = nomap_to_sysmem(ctx->dsdt); |
Maximilian Brune | 8dc4512 | 2024-10-23 15:19:45 +0200 | [diff] [blame] | 257 | |
| 258 | if (fadt->x_firmware_ctrl < 0x100000000ULL) |
| 259 | fadt->firmware_ctrl = fadt->x_firmware_ctrl; |
| 260 | |
| 261 | if (fadt->x_dsdt < 0x100000000ULL) |
| 262 | fadt->dsdt = fadt->x_dsdt; |
| 263 | |
| 264 | fadt->preferred_pm_profile = ACPI_PM_UNSPECIFIED; |
| 265 | |
| 266 | acpi_fill_fadt(fadt); |
| 267 | |
Heinrich Schuchardt | 7b332b5 | 2025-03-22 00:21:17 +0100 | [diff] [blame] | 268 | acpi_update_checksum(header); |
Maximilian Brune | 8dc4512 | 2024-10-23 15:19:45 +0200 | [diff] [blame] | 269 | |
| 270 | return acpi_add_fadt(ctx, fadt); |
| 271 | } |
| 272 | |
Heinrich Schuchardt | 0883971 | 2024-12-20 01:37:59 +0100 | [diff] [blame] | 273 | #ifndef CONFIG_QFW_ACPI |
Maximilian Brune | 8dc4512 | 2024-10-23 15:19:45 +0200 | [diff] [blame] | 274 | ACPI_WRITER(5fadt, "FADT", acpi_write_fadt, 0); |
Heinrich Schuchardt | 0883971 | 2024-12-20 01:37:59 +0100 | [diff] [blame] | 275 | #endif |
Maximilian Brune | 8dc4512 | 2024-10-23 15:19:45 +0200 | [diff] [blame] | 276 | |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame] | 277 | int acpi_write_madt(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
| 278 | { |
| 279 | struct acpi_table_header *header; |
| 280 | struct acpi_madt *madt; |
| 281 | void *current; |
| 282 | |
| 283 | madt = ctx->current; |
| 284 | |
| 285 | memset(madt, '\0', sizeof(struct acpi_madt)); |
| 286 | header = &madt->header; |
| 287 | |
| 288 | /* Fill out header fields */ |
| 289 | acpi_fill_header(header, "APIC"); |
| 290 | header->length = sizeof(struct acpi_madt); |
Patrick Rudolph | f317fce | 2024-10-23 15:19:52 +0200 | [diff] [blame] | 291 | header->revision = acpi_get_table_revision(ACPITAB_MADT); |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame] | 292 | |
| 293 | acpi_inc(ctx, sizeof(struct acpi_madt)); |
Patrick Rudolph | bff7c57 | 2024-10-23 15:19:51 +0200 | [diff] [blame] | 294 | /* TODO: Get rid of acpi_fill_madt and use driver model */ |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame] | 295 | current = acpi_fill_madt(madt, ctx); |
| 296 | |
| 297 | /* (Re)calculate length and checksum */ |
| 298 | header->length = (uintptr_t)current - (uintptr_t)madt; |
Patrick Rudolph | 2f6f8d9 | 2024-10-23 15:20:13 +0200 | [diff] [blame] | 299 | |
| 300 | if (IS_ENABLED(CONFIG_ACPI_PARKING_PROTOCOL)) |
| 301 | acpi_write_park(madt); |
| 302 | |
Heinrich Schuchardt | 7b332b5 | 2025-03-22 00:21:17 +0100 | [diff] [blame] | 303 | acpi_update_checksum(header); |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame] | 304 | acpi_add_table(ctx, madt); |
| 305 | ctx->current = (void *)madt + madt->header.length; |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
Heinrich Schuchardt | 0883971 | 2024-12-20 01:37:59 +0100 | [diff] [blame] | 310 | #ifndef CONFIG_QFW_ACPI |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame] | 311 | ACPI_WRITER(5madt, "MADT", acpi_write_madt, 0); |
Heinrich Schuchardt | 0883971 | 2024-12-20 01:37:59 +0100 | [diff] [blame] | 312 | #endif |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame] | 313 | |
Simon Glass | 9597189 | 2020-09-22 12:45:10 -0600 | [diff] [blame] | 314 | void acpi_create_dbg2(struct acpi_dbg2_header *dbg2, |
| 315 | int port_type, int port_subtype, |
| 316 | struct acpi_gen_regaddr *address, u32 address_size, |
| 317 | const char *device_path) |
| 318 | { |
| 319 | uintptr_t current; |
| 320 | struct acpi_dbg2_device *device; |
| 321 | u32 *dbg2_addr_size; |
| 322 | struct acpi_table_header *header; |
| 323 | size_t path_len; |
| 324 | const char *path; |
| 325 | char *namespace; |
| 326 | |
| 327 | /* Fill out header fields. */ |
| 328 | current = (uintptr_t)dbg2; |
| 329 | memset(dbg2, '\0', sizeof(struct acpi_dbg2_header)); |
| 330 | header = &dbg2->header; |
| 331 | |
| 332 | header->revision = acpi_get_table_revision(ACPITAB_DBG2); |
| 333 | acpi_fill_header(header, "DBG2"); |
Simon Glass | 9597189 | 2020-09-22 12:45:10 -0600 | [diff] [blame] | 334 | |
| 335 | /* One debug device defined */ |
| 336 | dbg2->devices_offset = sizeof(struct acpi_dbg2_header); |
| 337 | dbg2->devices_count = 1; |
| 338 | current += sizeof(struct acpi_dbg2_header); |
| 339 | |
| 340 | /* Device comes after the header */ |
| 341 | device = (struct acpi_dbg2_device *)current; |
| 342 | memset(device, 0, sizeof(struct acpi_dbg2_device)); |
| 343 | current += sizeof(struct acpi_dbg2_device); |
| 344 | |
| 345 | device->revision = 0; |
| 346 | device->address_count = 1; |
| 347 | device->port_type = port_type; |
| 348 | device->port_subtype = port_subtype; |
| 349 | |
| 350 | /* Base Address comes after device structure */ |
| 351 | memcpy((void *)current, address, sizeof(struct acpi_gen_regaddr)); |
| 352 | device->base_address_offset = current - (uintptr_t)device; |
| 353 | current += sizeof(struct acpi_gen_regaddr); |
| 354 | |
| 355 | /* Address Size comes after address structure */ |
| 356 | dbg2_addr_size = (uint32_t *)current; |
| 357 | device->address_size_offset = current - (uintptr_t)device; |
| 358 | *dbg2_addr_size = address_size; |
| 359 | current += sizeof(uint32_t); |
| 360 | |
| 361 | /* Namespace string comes last, use '.' if not provided */ |
| 362 | path = device_path ? : "."; |
| 363 | /* Namespace string length includes NULL terminator */ |
| 364 | path_len = strlen(path) + 1; |
| 365 | namespace = (char *)current; |
| 366 | device->namespace_string_length = path_len; |
| 367 | device->namespace_string_offset = current - (uintptr_t)device; |
| 368 | strncpy(namespace, path, path_len); |
| 369 | current += path_len; |
| 370 | |
| 371 | /* Update structure lengths and checksum */ |
| 372 | device->length = current - (uintptr_t)device; |
| 373 | header->length = current - (uintptr_t)dbg2; |
Heinrich Schuchardt | 7b332b5 | 2025-03-22 00:21:17 +0100 | [diff] [blame] | 374 | acpi_update_checksum(header); |
Simon Glass | 9597189 | 2020-09-22 12:45:10 -0600 | [diff] [blame] | 375 | } |
Maximilian Brune | d7fa54b | 2024-10-23 15:19:44 +0200 | [diff] [blame] | 376 | |
| 377 | int acpi_write_dbg2_pci_uart(struct acpi_ctx *ctx, struct udevice *dev, |
| 378 | uint access_size) |
| 379 | { |
| 380 | struct acpi_dbg2_header *dbg2 = ctx->current; |
| 381 | char path[ACPI_PATH_MAX]; |
| 382 | struct acpi_gen_regaddr address; |
| 383 | u64 addr; |
| 384 | int ret; |
| 385 | |
| 386 | if (!device_active(dev)) { |
| 387 | log_info("Device not enabled\n"); |
| 388 | return -EACCES; |
| 389 | } |
| 390 | /* |
| 391 | * PCI devices don't remember their resource allocation information in |
| 392 | * U-Boot at present. We assume that MMIO is used for the UART and that |
| 393 | * the address space is 32 bytes: ns16550 uses 8 registers of up to |
| 394 | * 32-bits each. This is only for debugging so it is not a big deal. |
| 395 | */ |
| 396 | addr = dm_pci_read_bar32(dev, 0); |
| 397 | log_debug("UART addr %lx\n", (ulong)addr); |
| 398 | |
| 399 | ret = acpi_device_path(dev, path, sizeof(path)); |
| 400 | if (ret) |
| 401 | return log_msg_ret("path", ret); |
| 402 | |
| 403 | memset(&address, '\0', sizeof(address)); |
| 404 | address.space_id = ACPI_ADDRESS_SPACE_MEMORY; |
| 405 | address.addrl = (uint32_t)addr; |
| 406 | address.addrh = (uint32_t)((addr >> 32) & 0xffffffff); |
| 407 | address.access_size = access_size; |
| 408 | |
| 409 | ret = acpi_device_path(dev, path, sizeof(path)); |
| 410 | if (ret) |
| 411 | return log_msg_ret("path", ret); |
| 412 | acpi_create_dbg2(dbg2, ACPI_DBG2_SERIAL_PORT, |
| 413 | ACPI_DBG2_16550_COMPATIBLE, &address, 0x1000, path); |
| 414 | |
| 415 | acpi_inc_align(ctx, dbg2->header.length); |
| 416 | acpi_add_table(ctx, dbg2); |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | static int acpi_write_spcr(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
| 422 | { |
| 423 | struct serial_device_info serial_info = {0}; |
Patrick Rudolph | 1bf4cb2 | 2024-10-30 14:11:46 +0100 | [diff] [blame] | 424 | u64 serial_address, serial_offset; |
Maximilian Brune | d7fa54b | 2024-10-23 15:19:44 +0200 | [diff] [blame] | 425 | struct acpi_table_header *header; |
| 426 | struct acpi_spcr *spcr; |
| 427 | struct udevice *dev; |
| 428 | uint serial_config; |
| 429 | uint serial_width; |
| 430 | int access_size; |
| 431 | int space_id; |
| 432 | int ret = -ENODEV; |
| 433 | |
| 434 | spcr = ctx->current; |
| 435 | header = &spcr->header; |
| 436 | |
| 437 | memset(spcr, '\0', sizeof(struct acpi_spcr)); |
| 438 | |
| 439 | /* Fill out header fields */ |
| 440 | acpi_fill_header(header, "SPCR"); |
| 441 | header->length = sizeof(struct acpi_spcr); |
| 442 | header->revision = 2; |
| 443 | |
| 444 | /* Read the device once, here. It is reused below */ |
| 445 | dev = gd->cur_serial_dev; |
| 446 | if (dev) |
| 447 | ret = serial_getinfo(dev, &serial_info); |
| 448 | if (ret) |
| 449 | serial_info.type = SERIAL_CHIP_UNKNOWN; |
| 450 | |
| 451 | /* Encode chip type */ |
| 452 | switch (serial_info.type) { |
| 453 | case SERIAL_CHIP_16550_COMPATIBLE: |
| 454 | spcr->interface_type = ACPI_DBG2_16550_COMPATIBLE; |
| 455 | break; |
| 456 | case SERIAL_CHIP_PL01X: |
| 457 | spcr->interface_type = ACPI_DBG2_ARM_PL011; |
| 458 | break; |
| 459 | case SERIAL_CHIP_UNKNOWN: |
| 460 | default: |
| 461 | spcr->interface_type = ACPI_DBG2_UNKNOWN; |
| 462 | break; |
| 463 | } |
| 464 | |
| 465 | /* Encode address space */ |
| 466 | switch (serial_info.addr_space) { |
| 467 | case SERIAL_ADDRESS_SPACE_MEMORY: |
| 468 | space_id = ACPI_ADDRESS_SPACE_MEMORY; |
| 469 | break; |
| 470 | case SERIAL_ADDRESS_SPACE_IO: |
| 471 | default: |
| 472 | space_id = ACPI_ADDRESS_SPACE_IO; |
| 473 | break; |
| 474 | } |
| 475 | |
| 476 | serial_width = serial_info.reg_width * 8; |
Patrick Rudolph | 1bf4cb2 | 2024-10-30 14:11:46 +0100 | [diff] [blame] | 477 | serial_offset = ((u64)serial_info.reg_offset) << serial_info.reg_shift; |
Maximilian Brune | d7fa54b | 2024-10-23 15:19:44 +0200 | [diff] [blame] | 478 | serial_address = serial_info.addr + serial_offset; |
| 479 | |
| 480 | /* Encode register access size */ |
| 481 | switch (serial_info.reg_shift) { |
| 482 | case 0: |
| 483 | access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
| 484 | break; |
| 485 | case 1: |
| 486 | access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
| 487 | break; |
| 488 | case 2: |
| 489 | access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 490 | break; |
| 491 | case 3: |
| 492 | access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS; |
| 493 | break; |
| 494 | default: |
| 495 | access_size = ACPI_ACCESS_SIZE_UNDEFINED; |
| 496 | break; |
| 497 | } |
| 498 | |
Patrick Rudolph | 1bf4cb2 | 2024-10-30 14:11:46 +0100 | [diff] [blame] | 499 | debug("UART type %u @ %llx\n", spcr->interface_type, serial_address); |
Maximilian Brune | d7fa54b | 2024-10-23 15:19:44 +0200 | [diff] [blame] | 500 | |
| 501 | /* Fill GAS */ |
| 502 | spcr->serial_port.space_id = space_id; |
| 503 | spcr->serial_port.bit_width = serial_width; |
| 504 | spcr->serial_port.bit_offset = 0; |
| 505 | spcr->serial_port.access_size = access_size; |
| 506 | spcr->serial_port.addrl = lower_32_bits(serial_address); |
| 507 | spcr->serial_port.addrh = upper_32_bits(serial_address); |
| 508 | |
| 509 | /* Encode baud rate */ |
| 510 | switch (serial_info.baudrate) { |
| 511 | case 9600: |
| 512 | spcr->baud_rate = 3; |
| 513 | break; |
| 514 | case 19200: |
| 515 | spcr->baud_rate = 4; |
| 516 | break; |
| 517 | case 57600: |
| 518 | spcr->baud_rate = 6; |
| 519 | break; |
| 520 | case 115200: |
| 521 | spcr->baud_rate = 7; |
| 522 | break; |
| 523 | default: |
| 524 | spcr->baud_rate = 0; |
| 525 | break; |
| 526 | } |
| 527 | |
| 528 | serial_config = SERIAL_DEFAULT_CONFIG; |
| 529 | if (dev) |
| 530 | ret = serial_getconfig(dev, &serial_config); |
| 531 | |
| 532 | spcr->parity = SERIAL_GET_PARITY(serial_config); |
| 533 | spcr->stop_bits = SERIAL_GET_STOP(serial_config); |
| 534 | |
| 535 | /* No PCI devices for now */ |
| 536 | spcr->pci_device_id = 0xffff; |
| 537 | spcr->pci_vendor_id = 0xffff; |
| 538 | |
| 539 | /* |
| 540 | * SPCR has no clue if the UART base clock speed is different |
| 541 | * to the default one. However, the SPCR 1.04 defines baud rate |
| 542 | * 0 as a preconfigured state of UART and OS is supposed not |
| 543 | * to touch the configuration of the serial device. |
| 544 | */ |
| 545 | if (serial_info.clock != SERIAL_DEFAULT_CLOCK) |
| 546 | spcr->baud_rate = 0; |
| 547 | |
| 548 | /* Fix checksum */ |
Heinrich Schuchardt | 7b332b5 | 2025-03-22 00:21:17 +0100 | [diff] [blame] | 549 | acpi_update_checksum(header); |
Maximilian Brune | d7fa54b | 2024-10-23 15:19:44 +0200 | [diff] [blame] | 550 | |
| 551 | acpi_add_table(ctx, spcr); |
| 552 | acpi_inc(ctx, spcr->header.length); |
| 553 | |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | ACPI_WRITER(5spcr, "SPCR", acpi_write_spcr, 0); |
Patrick Rudolph | 1669ce7 | 2024-10-23 15:19:54 +0200 | [diff] [blame] | 558 | |
| 559 | __weak int acpi_fill_iort(struct acpi_ctx *ctx) |
| 560 | { |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | int acpi_iort_add_its_group(struct acpi_ctx *ctx, |
| 565 | const u32 its_count, |
| 566 | const u32 *identifiers) |
| 567 | { |
| 568 | struct acpi_iort_node *node; |
| 569 | struct acpi_iort_its_group *group; |
| 570 | int offset; |
| 571 | |
| 572 | offset = ctx->current - ctx->tab_start; |
| 573 | |
| 574 | node = ctx->current; |
| 575 | memset(node, '\0', sizeof(struct acpi_iort_node)); |
| 576 | |
| 577 | node->type = ACPI_IORT_NODE_ITS_GROUP; |
| 578 | node->revision = 1; |
| 579 | |
| 580 | node->length = sizeof(struct acpi_iort_node); |
| 581 | node->length += sizeof(struct acpi_iort_its_group); |
| 582 | node->length += sizeof(u32) * its_count; |
| 583 | |
| 584 | group = (struct acpi_iort_its_group *)node->node_data; |
| 585 | group->its_count = its_count; |
| 586 | memcpy(&group->identifiers, identifiers, sizeof(u32) * its_count); |
| 587 | |
| 588 | ctx->current += node->length; |
| 589 | |
| 590 | return offset; |
| 591 | } |
| 592 | |
| 593 | int acpi_iort_add_named_component(struct acpi_ctx *ctx, |
| 594 | const u32 node_flags, |
| 595 | const u64 memory_properties, |
| 596 | const u8 memory_address_limit, |
| 597 | const char *device_name) |
| 598 | { |
| 599 | struct acpi_iort_node *node; |
| 600 | struct acpi_iort_named_component *comp; |
| 601 | int offset; |
| 602 | |
| 603 | offset = ctx->current - ctx->tab_start; |
| 604 | |
| 605 | node = ctx->current; |
| 606 | memset(node, '\0', sizeof(struct acpi_iort_node)); |
| 607 | |
| 608 | node->type = ACPI_IORT_NODE_NAMED_COMPONENT; |
| 609 | node->revision = 4; |
| 610 | node->length = sizeof(struct acpi_iort_node); |
| 611 | node->length += sizeof(struct acpi_iort_named_component); |
| 612 | node->length += strlen(device_name) + 1; |
| 613 | |
| 614 | comp = (struct acpi_iort_named_component *)node->node_data; |
Patrick Rudolph | 0eafaf2 | 2025-03-16 09:32:54 +0100 | [diff] [blame] | 615 | memset(comp, '\0', sizeof(struct acpi_iort_named_component)); |
Patrick Rudolph | 1669ce7 | 2024-10-23 15:19:54 +0200 | [diff] [blame] | 616 | |
| 617 | comp->node_flags = node_flags; |
| 618 | comp->memory_properties = memory_properties; |
| 619 | comp->memory_address_limit = memory_address_limit; |
| 620 | memcpy(comp->device_name, device_name, strlen(device_name) + 1); |
| 621 | |
| 622 | ctx->current += node->length; |
| 623 | |
| 624 | return offset; |
| 625 | } |
| 626 | |
| 627 | int acpi_iort_add_rc(struct acpi_ctx *ctx, |
| 628 | const u64 mem_access_properties, |
| 629 | const u32 ats_attributes, |
| 630 | const u32 pci_segment_number, |
| 631 | const u8 memory_address_size_limit, |
| 632 | const int num_mappings, |
| 633 | const struct acpi_iort_id_mapping *map) |
| 634 | { |
| 635 | struct acpi_iort_id_mapping *mapping; |
Patrick Rudolph | 9b6b388 | 2025-03-16 09:32:53 +0100 | [diff] [blame] | 636 | struct acpi_iort_node *output_node; |
Patrick Rudolph | 1669ce7 | 2024-10-23 15:19:54 +0200 | [diff] [blame] | 637 | struct acpi_iort_node *node; |
| 638 | struct acpi_iort_rc *rc; |
| 639 | int offset; |
| 640 | |
| 641 | offset = ctx->current - ctx->tab_start; |
| 642 | |
| 643 | node = ctx->current; |
| 644 | memset(node, '\0', sizeof(struct acpi_iort_node)); |
| 645 | |
| 646 | node->type = ACPI_IORT_NODE_PCI_ROOT_COMPLEX; |
| 647 | node->revision = 2; |
Patrick Rudolph | fcfbecb | 2025-03-16 09:32:52 +0100 | [diff] [blame] | 648 | node->mapping_count = num_mappings; |
Patrick Rudolph | 15b48eb | 2025-03-16 09:32:55 +0100 | [diff] [blame] | 649 | if (num_mappings) |
| 650 | node->mapping_offset = sizeof(struct acpi_iort_node) + |
| 651 | sizeof(struct acpi_iort_rc); |
Patrick Rudolph | 1669ce7 | 2024-10-23 15:19:54 +0200 | [diff] [blame] | 652 | |
| 653 | node->length = sizeof(struct acpi_iort_node); |
| 654 | node->length += sizeof(struct acpi_iort_rc); |
| 655 | node->length += sizeof(struct acpi_iort_id_mapping) * num_mappings; |
| 656 | |
| 657 | rc = (struct acpi_iort_rc *)node->node_data; |
Patrick Rudolph | 0eafaf2 | 2025-03-16 09:32:54 +0100 | [diff] [blame] | 658 | memset(rc, '\0', sizeof(struct acpi_iort_rc)); |
| 659 | |
Patrick Rudolph | 1669ce7 | 2024-10-23 15:19:54 +0200 | [diff] [blame] | 660 | rc->mem_access_properties = mem_access_properties; |
| 661 | rc->ats_attributes = ats_attributes; |
| 662 | rc->pci_segment_number = pci_segment_number; |
| 663 | rc->memory_address_size_limit = memory_address_size_limit; |
| 664 | |
| 665 | mapping = (struct acpi_iort_id_mapping *)(rc + 1); |
| 666 | for (int i = 0; i < num_mappings; i++) { |
Patrick Rudolph | 9b6b388 | 2025-03-16 09:32:53 +0100 | [diff] [blame] | 667 | /* Validate input */ |
| 668 | output_node = (struct acpi_iort_node *)ctx->tab_start + map[i].output_reference; |
| 669 | /* ID mappings can use SMMUs or ITS groups as output references */ |
| 670 | assert(output_node && ((output_node->type == ACPI_IORT_NODE_ITS_GROUP) || |
| 671 | (output_node->type == ACPI_IORT_NODE_SMMU) || |
| 672 | (output_node->type == ACPI_IORT_NODE_SMMU_V3))); |
| 673 | |
Patrick Rudolph | 1669ce7 | 2024-10-23 15:19:54 +0200 | [diff] [blame] | 674 | memcpy(mapping, &map[i], sizeof(struct acpi_iort_id_mapping)); |
| 675 | mapping++; |
| 676 | } |
| 677 | |
| 678 | ctx->current += node->length; |
| 679 | |
| 680 | return offset; |
| 681 | } |
| 682 | |
| 683 | int acpi_iort_add_smmu_v3(struct acpi_ctx *ctx, |
| 684 | const u64 base_address, |
| 685 | const u32 flags, |
| 686 | const u64 vatos_address, |
| 687 | const u32 model, |
| 688 | const u32 event_gsiv, |
| 689 | const u32 pri_gsiv, |
| 690 | const u32 gerr_gsiv, |
| 691 | const u32 sync_gsiv, |
| 692 | const u32 pxm, |
| 693 | const u32 id_mapping_index, |
| 694 | const int num_mappings, |
| 695 | const struct acpi_iort_id_mapping *map) |
| 696 | { |
| 697 | struct acpi_iort_node *node; |
Patrick Rudolph | 9b6b388 | 2025-03-16 09:32:53 +0100 | [diff] [blame] | 698 | struct acpi_iort_node *output_node; |
Patrick Rudolph | 1669ce7 | 2024-10-23 15:19:54 +0200 | [diff] [blame] | 699 | struct acpi_iort_smmu_v3 *smmu; |
| 700 | struct acpi_iort_id_mapping *mapping; |
| 701 | int offset; |
| 702 | |
| 703 | offset = ctx->current - ctx->tab_start; |
| 704 | |
| 705 | node = ctx->current; |
| 706 | memset(node, '\0', sizeof(struct acpi_iort_node)); |
| 707 | |
| 708 | node->type = ACPI_IORT_NODE_SMMU_V3; |
| 709 | node->revision = 5; |
| 710 | node->mapping_count = num_mappings; |
Patrick Rudolph | 15b48eb | 2025-03-16 09:32:55 +0100 | [diff] [blame] | 711 | if (num_mappings) |
| 712 | node->mapping_offset = sizeof(struct acpi_iort_node) + |
| 713 | sizeof(struct acpi_iort_smmu_v3); |
Patrick Rudolph | 1669ce7 | 2024-10-23 15:19:54 +0200 | [diff] [blame] | 714 | |
| 715 | node->length = sizeof(struct acpi_iort_node); |
| 716 | node->length += sizeof(struct acpi_iort_smmu_v3); |
| 717 | node->length += sizeof(struct acpi_iort_id_mapping) * num_mappings; |
| 718 | |
| 719 | smmu = (struct acpi_iort_smmu_v3 *)node->node_data; |
Patrick Rudolph | 0eafaf2 | 2025-03-16 09:32:54 +0100 | [diff] [blame] | 720 | memset(smmu, '\0', sizeof(struct acpi_iort_smmu_v3)); |
Patrick Rudolph | 1669ce7 | 2024-10-23 15:19:54 +0200 | [diff] [blame] | 721 | |
| 722 | smmu->base_address = base_address; |
| 723 | smmu->flags = flags; |
| 724 | smmu->vatos_address = vatos_address; |
| 725 | smmu->model = model; |
| 726 | smmu->event_gsiv = event_gsiv; |
| 727 | smmu->pri_gsiv = pri_gsiv; |
| 728 | smmu->gerr_gsiv = gerr_gsiv; |
| 729 | smmu->sync_gsiv = sync_gsiv; |
| 730 | smmu->pxm = pxm; |
| 731 | smmu->id_mapping_index = id_mapping_index; |
| 732 | |
| 733 | mapping = (struct acpi_iort_id_mapping *)(smmu + 1); |
| 734 | for (int i = 0; i < num_mappings; i++) { |
Patrick Rudolph | 9b6b388 | 2025-03-16 09:32:53 +0100 | [diff] [blame] | 735 | /* Validate input */ |
| 736 | output_node = (struct acpi_iort_node *)ctx->tab_start + map[i].output_reference; |
| 737 | /* |
| 738 | * ID mappings of an SMMUv3 node can only have ITS group nodes |
| 739 | * as output references. |
| 740 | */ |
| 741 | assert(output_node && output_node->type == ACPI_IORT_NODE_ITS_GROUP); |
| 742 | |
Patrick Rudolph | 1669ce7 | 2024-10-23 15:19:54 +0200 | [diff] [blame] | 743 | memcpy(mapping, &map[i], sizeof(struct acpi_iort_id_mapping)); |
| 744 | mapping++; |
| 745 | } |
| 746 | |
| 747 | ctx->current += node->length; |
| 748 | |
| 749 | return offset; |
| 750 | } |
| 751 | |
| 752 | static int acpi_write_iort(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
| 753 | { |
| 754 | struct acpi_table_iort *iort; |
| 755 | struct acpi_iort_node *node; |
| 756 | u32 offset; |
| 757 | int ret; |
| 758 | |
| 759 | iort = ctx->current; |
| 760 | ctx->tab_start = ctx->current; |
| 761 | memset(iort, '\0', sizeof(struct acpi_table_iort)); |
| 762 | |
| 763 | acpi_fill_header(&iort->header, "IORT"); |
| 764 | iort->header.revision = 1; |
| 765 | iort->header.creator_revision = 1; |
| 766 | iort->header.length = sizeof(struct acpi_table_iort); |
| 767 | iort->node_offset = sizeof(struct acpi_table_iort); |
| 768 | |
| 769 | acpi_inc(ctx, sizeof(struct acpi_table_iort)); |
| 770 | |
| 771 | offset = sizeof(struct acpi_table_iort); |
| 772 | ret = acpi_fill_iort(ctx); |
| 773 | if (ret) { |
| 774 | ctx->current = iort; |
| 775 | return log_msg_ret("fill", ret); |
| 776 | } |
| 777 | |
| 778 | /* Count nodes filled in */ |
| 779 | for (node = (void *)iort + iort->node_offset; |
| 780 | node->length > 0 && (void *)node < ctx->current; |
| 781 | node = (void *)node + node->length) |
| 782 | iort->node_count++; |
| 783 | |
| 784 | /* (Re)calculate length and checksum */ |
| 785 | iort->header.length = ctx->current - (void *)iort; |
Heinrich Schuchardt | 7b332b5 | 2025-03-22 00:21:17 +0100 | [diff] [blame] | 786 | acpi_update_checksum(&iort->header); |
Patrick Rudolph | 1669ce7 | 2024-10-23 15:19:54 +0200 | [diff] [blame] | 787 | log_debug("IORT at %p, length %x\n", iort, iort->header.length); |
| 788 | |
| 789 | /* Drop the table if it is empty */ |
| 790 | if (iort->header.length == sizeof(struct acpi_table_iort)) |
| 791 | return log_msg_ret("fill", -ENOENT); |
| 792 | acpi_add_table(ctx, iort); |
| 793 | |
| 794 | return 0; |
| 795 | } |
| 796 | |
| 797 | ACPI_WRITER(5iort, "IORT", acpi_write_iort, 0); |
Patrick Rudolph | 158efd6 | 2024-10-23 15:19:57 +0200 | [diff] [blame] | 798 | |
| 799 | /* |
| 800 | * Allocate memory for ACPI tables and write ACPI tables to the |
| 801 | * allocated buffer. |
| 802 | * |
| 803 | * Return: status code |
| 804 | */ |
| 805 | static int alloc_write_acpi_tables(void) |
| 806 | { |
| 807 | u64 table_end; |
| 808 | void *addr; |
| 809 | |
| 810 | if (IS_ENABLED(CONFIG_X86) || |
| 811 | IS_ENABLED(CONFIG_QFW_ACPI) || |
| 812 | IS_ENABLED(CONFIG_SANDBOX)) { |
| 813 | log_debug("Skipping writing ACPI tables as already done\n"); |
| 814 | return 0; |
| 815 | } |
| 816 | |
| 817 | if (!IS_ENABLED(CONFIG_BLOBLIST_TABLES)) { |
| 818 | log_debug("Skipping writing ACPI tables as BLOBLIST_TABLES is not selected\n"); |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | /* Align the table to a 4KB boundary to keep EFI happy */ |
| 823 | addr = bloblist_add(BLOBLISTT_ACPI_TABLES, TABLE_SIZE, |
| 824 | ilog2(SZ_4K)); |
| 825 | |
| 826 | if (!addr) |
| 827 | return log_msg_ret("mem", -ENOMEM); |
| 828 | |
| 829 | gd->arch.table_start_high = virt_to_phys(addr); |
| 830 | gd->arch.table_end_high = gd->arch.table_start_high + TABLE_SIZE; |
| 831 | |
| 832 | table_end = write_acpi_tables(gd->arch.table_start_high); |
| 833 | if (!table_end) { |
| 834 | log_err("Can't create ACPI configuration table\n"); |
| 835 | return -EINTR; |
| 836 | } |
| 837 | |
| 838 | log_debug("- wrote 'acpi' to %lx, end %llx\n", gd->arch.table_start_high, table_end); |
| 839 | if (table_end > gd->arch.table_end_high) { |
| 840 | log_err("Out of space for configuration tables: need %llx, have %x\n", |
| 841 | table_end - gd->arch.table_start_high, TABLE_SIZE); |
| 842 | return log_msg_ret("acpi", -ENOSPC); |
| 843 | } |
| 844 | |
| 845 | log_debug("- done writing tables\n"); |
| 846 | |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, alloc_write_acpi_tables); |