
From: Simon Glass <sjg@chromium.org> The acpi_table.c file includes ACPI_WRITER() declarations and is only included in the build if CONFIG_ACPIGEN is enabled. For QEMU we want to augment the tables provided via qfw, but CONFIG_ACPIGEN is not enabled. Move the core functions out to the acpi.c file which is included in all x86 builds. This allows the QEMU build to make use of these functions. Signed-off-by: Simon Glass <sjg@chromium.org> --- lib/acpi/acpi.c | 122 ++++++++++++++++++++++++++++++++++++++++++ lib/acpi/acpi_table.c | 122 ------------------------------------------ 2 files changed, 122 insertions(+), 122 deletions(-) diff --git a/lib/acpi/acpi.c b/lib/acpi/acpi.c index 01cc606d61c..dc327dc08c7 100644 --- a/lib/acpi/acpi.c +++ b/lib/acpi/acpi.c @@ -10,11 +10,28 @@ #include <errno.h> #include <mapmem.h> #include <tables_csum.h> +#include <version_string.h> #include <acpi/acpi_table.h> #include <asm/global_data.h> DECLARE_GLOBAL_DATA_PTR; +/* + * OEM_REVISION is 32-bit unsigned number. It should be increased only when + * changing software version. Therefore it should not depend on build time. + * U-Boot calculates it from U-Boot version and represent it in hexadecimal + * notation. As U-Boot version is in form year.month set low 8 bits to 0x01 + * to have valid date. So for U-Boot version 2021.04 OEM_REVISION is set to + * value 0x20210401. + */ +#define OEM_REVISION ((((version_num / 1000) % 10) << 28) | \ + (((version_num / 100) % 10) << 24) | \ + (((version_num / 10) % 10) << 20) | \ + ((version_num % 10) << 16) | \ + (((version_num_patch / 10) % 10) << 12) | \ + ((version_num_patch % 10) << 8) | \ + 0x01) + void acpi_update_checksum(struct acpi_table_header *header) { header->checksum = 0; @@ -145,3 +162,108 @@ struct acpi_table_header *acpi_find_table(const char *sig) return NULL; } + +void acpi_fill_header(struct acpi_table_header *header, char *signature) +{ + memcpy(header->signature, signature, 4); + memcpy(header->oem_id, OEM_ID, 6); + memcpy(header->oem_table_id, OEM_TABLE_ID, 8); + header->oem_revision = OEM_REVISION; + memcpy(header->creator_id, ASLC_ID, 4); + header->creator_revision = ASL_REVISION; +} + +void acpi_align(struct acpi_ctx *ctx) +{ + ctx->current = (void *)ALIGN((ulong)ctx->current, 16); +} + +void acpi_align64(struct acpi_ctx *ctx) +{ + ctx->current = (void *)ALIGN((ulong)ctx->current, 64); +} + +void acpi_inc(struct acpi_ctx *ctx, uint amount) +{ + ctx->current += amount; +} + +void acpi_inc_align(struct acpi_ctx *ctx, uint amount) +{ + ctx->current += amount; + acpi_align(ctx); +} + +/** + * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length + * and checksum. + */ +int acpi_add_table(struct acpi_ctx *ctx, void *table) +{ + int i, entries_num; + struct acpi_rsdt *rsdt; + struct acpi_xsdt *xsdt; + + /* On legacy x86 platforms the RSDT is mandatory while the XSDT is not. + * On other platforms there might be no memory below 4GiB, thus RSDT is NULL. + */ + if (ctx->rsdt) { + rsdt = ctx->rsdt; + + /* This should always be MAX_ACPI_TABLES */ + entries_num = ARRAY_SIZE(rsdt->entry); + + for (i = 0; i < entries_num; i++) { + if (rsdt->entry[i] == 0) + break; + } + + if (i >= entries_num) { + log_err("ACPI: Error: too many tables\n"); + return -E2BIG; + } + + /* Add table to the RSDT */ + rsdt->entry[i] = nomap_to_sysmem(table); + + /* Fix RSDT length or the kernel will assume invalid entries */ + rsdt->header.length = sizeof(struct acpi_table_header) + + (sizeof(u32) * (i + 1)); + + /* Re-calculate checksum */ + acpi_update_checksum(&rsdt->header); + } + + if (ctx->xsdt) { + /* + * And now the same thing for the XSDT. We use the same index as for + * now we want the XSDT and RSDT to always be in sync in U-Boot + */ + xsdt = ctx->xsdt; + + /* This should always be MAX_ACPI_TABLES */ + entries_num = ARRAY_SIZE(xsdt->entry); + + for (i = 0; i < entries_num; i++) { + if (xsdt->entry[i] == 0) + break; + } + + if (i >= entries_num) { + log_err("ACPI: Error: too many tables\n"); + return -E2BIG; + } + + /* Add table to the XSDT */ + xsdt->entry[i] = nomap_to_sysmem(table); + + /* Fix XSDT length */ + xsdt->header.length = sizeof(struct acpi_table_header) + + (sizeof(u64) * (i + 1)); + + /* Re-calculate checksum */ + acpi_update_checksum(&xsdt->header); + } + + return 0; +} diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index 84d60f74c1c..8423786fff3 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -14,7 +14,6 @@ #include <mapmem.h> #include <tables_csum.h> #include <serial.h> -#include <version_string.h> #include <acpi/acpi_table.h> #include <acpi/acpi_device.h> #include <asm/global_data.h> @@ -28,22 +27,6 @@ enum { DECLARE_GLOBAL_DATA_PTR; -/* - * OEM_REVISION is 32-bit unsigned number. It should be increased only when - * changing software version. Therefore it should not depend on build time. - * U-Boot calculates it from U-Boot version and represent it in hexadecimal - * notation. As U-Boot version is in form year.month set low 8 bits to 0x01 - * to have valid date. So for U-Boot version 2021.04 OEM_REVISION is set to - * value 0x20210401. - */ -#define OEM_REVISION ((((version_num / 1000) % 10) << 28) | \ - (((version_num / 100) % 10) << 24) | \ - (((version_num / 10) % 10) << 20) | \ - ((version_num % 10) << 16) | \ - (((version_num_patch / 10) % 10) << 12) | \ - ((version_num_patch % 10) << 8) | \ - 0x01) - int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags) { struct acpi_table_header *header = &dmar->header; @@ -128,111 +111,6 @@ int acpi_get_table_revision(enum acpi_tables table) } } -void acpi_fill_header(struct acpi_table_header *header, char *signature) -{ - memcpy(header->signature, signature, 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, OEM_TABLE_ID, 8); - header->oem_revision = OEM_REVISION; - memcpy(header->creator_id, ASLC_ID, 4); - header->creator_revision = ASL_REVISION; -} - -void acpi_align(struct acpi_ctx *ctx) -{ - ctx->current = (void *)ALIGN((ulong)ctx->current, 16); -} - -void acpi_align64(struct acpi_ctx *ctx) -{ - ctx->current = (void *)ALIGN((ulong)ctx->current, 64); -} - -void acpi_inc(struct acpi_ctx *ctx, uint amount) -{ - ctx->current += amount; -} - -void acpi_inc_align(struct acpi_ctx *ctx, uint amount) -{ - ctx->current += amount; - acpi_align(ctx); -} - -/** - * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length - * and checksum. - */ -int acpi_add_table(struct acpi_ctx *ctx, void *table) -{ - int i, entries_num; - struct acpi_rsdt *rsdt; - struct acpi_xsdt *xsdt; - - /* On legacy x86 platforms the RSDT is mandatory while the XSDT is not. - * On other platforms there might be no memory below 4GiB, thus RSDT is NULL. - */ - if (ctx->rsdt) { - rsdt = ctx->rsdt; - - /* This should always be MAX_ACPI_TABLES */ - entries_num = ARRAY_SIZE(rsdt->entry); - - for (i = 0; i < entries_num; i++) { - if (rsdt->entry[i] == 0) - break; - } - - if (i >= entries_num) { - log_err("ACPI: Error: too many tables\n"); - return -E2BIG; - } - - /* Add table to the RSDT */ - rsdt->entry[i] = nomap_to_sysmem(table); - - /* Fix RSDT length or the kernel will assume invalid entries */ - rsdt->header.length = sizeof(struct acpi_table_header) + - (sizeof(u32) * (i + 1)); - - /* Re-calculate checksum */ - acpi_update_checksum(&rsdt->header); - } - - if (ctx->xsdt) { - /* - * And now the same thing for the XSDT. We use the same index as for - * now we want the XSDT and RSDT to always be in sync in U-Boot - */ - xsdt = ctx->xsdt; - - /* This should always be MAX_ACPI_TABLES */ - entries_num = ARRAY_SIZE(xsdt->entry); - - for (i = 0; i < entries_num; i++) { - if (xsdt->entry[i] == 0) - break; - } - - if (i >= entries_num) { - log_err("ACPI: Error: too many tables\n"); - return -E2BIG; - } - - /* Add table to the XSDT */ - xsdt->entry[i] = nomap_to_sysmem(table); - - /* Fix XSDT length */ - xsdt->header.length = sizeof(struct acpi_table_header) + - (sizeof(u64) * (i + 1)); - - /* Re-calculate checksum */ - acpi_update_checksum(&xsdt->header); - } - - return 0; -} - int acpi_write_fadt(struct acpi_ctx *ctx, const struct acpi_writer *entry) { struct acpi_table_header *header; -- 2.43.0