From patchwork Wed Oct 29 06:16:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 645 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1761718639; bh=TPd5R51DYy7COM7yXUq/DoP5jWzaPwsRcJ+LxQs5Z58=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=BuJQY3dX6HzkwfFTOYv2O6tDhvIjAqND20UTCYLNSoFG7k01+nB9dhtZaQqWY64yA 0hHoj5FHR5bHv1VpCHNiDe8RFyASzVnnxFdki5ddf7kllTrNG+Sn1nnDxKLhdbePjv 6oxua9/DB0EDxa68sGK8cyixfMLsKSCxu++fHO5ZbSujYqMXn4++VcTSKQ9DZulkJA /b+9Ovnfg7ulEMEcQZDE27MB12+RAMLKivBXQ4Bj4N+6XMVK6Gm3A+uLf7OIQE4L+8 N9UmjnFgWA57oYQght2tu/ff2O/bQ6OSwCdWoC3X2yxeNCkhPRr9HJW1D79JxGzls5 Oze6MJ7T5BXpg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7849968303 for ; Wed, 29 Oct 2025 00:17:19 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 4dNwNeFim3OS for ; Wed, 29 Oct 2025 00:17:19 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1761718639; bh=TPd5R51DYy7COM7yXUq/DoP5jWzaPwsRcJ+LxQs5Z58=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=BuJQY3dX6HzkwfFTOYv2O6tDhvIjAqND20UTCYLNSoFG7k01+nB9dhtZaQqWY64yA 0hHoj5FHR5bHv1VpCHNiDe8RFyASzVnnxFdki5ddf7kllTrNG+Sn1nnDxKLhdbePjv 6oxua9/DB0EDxa68sGK8cyixfMLsKSCxu++fHO5ZbSujYqMXn4++VcTSKQ9DZulkJA /b+9Ovnfg7ulEMEcQZDE27MB12+RAMLKivBXQ4Bj4N+6XMVK6Gm3A+uLf7OIQE4L+8 N9UmjnFgWA57oYQght2tu/ff2O/bQ6OSwCdWoC3X2yxeNCkhPRr9HJW1D79JxGzls5 Oze6MJ7T5BXpg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 670E86830C for ; Wed, 29 Oct 2025 00:17:19 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1761718637; bh=ix/FfVYS0pw6mR5l0kOTxD/lBQfKgOIDGREYQSreXgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BMrGpgRyiXbkrLsI4hx1rj8lWfn4BPblsfqVbzHzKWjJbT1V3+MmSzx2NSAH3eQQz mwBmeXgDqFmnxrRPbgF3kgtZl15H0uEPTE1cX49VTJ+lojSLRP4GwZFvBe7Me+byNH 2ZhANOW9ad7Ltfat8xCVUFk+oMaNB+EAGhlv6iB7wAHsC1iBMpjmqSuqcMJs4Du6pH jDV73P2KjWM32Vlxdi6HGSUkp6cy2YDUT8A9iQmRVXuY0bNZA9B1Ctj0g4Z//Rxg/R dt1zcYOF2UVLhvuYUh8XC+8nJthU3278ly+KahgPLz3tSGsD1Veltl4ApzZH8zkSAX a6laM1lBs5G0w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6E45368303; Wed, 29 Oct 2025 00:17:17 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id WTwMh2ohRrBX; Wed, 29 Oct 2025 00:17:17 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1761718633; bh=/4x2kwfdcKSesiM17NggA46beUmg+2havIpg8x5l1Wg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lCoFQA0mgox9btrpicKAL8MegtFg0pVib6ybPJ3mEfxeUvQMlOPrSjHtLaYedNPLz hpJ3isY4bftS+hthadFnqT1eU6oo7Suf3MJqLUba/hqSxdYQreUb8tai/ZBIrmxIgp fCzDQ7D3INbY96572IhAS1DCFCAELAQhsfkwefft9KGCAiple/OUoknJQXO46SjbVo pCkYhONlWlaX9/2oPrBMRwMjx+HL5vjE9bqKppOsmQhqO4ULPbhJknCc/CyrQfkD5B miyuLym/iThVX88grboPqGegSaCnyWpq17ivx4pmfnw+lFK7gy1pCqBdqu3nH1XpVE kEoPz+41UIyiw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 15EA4682D9; Wed, 29 Oct 2025 00:17:13 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Wed, 29 Oct 2025 00:16:43 -0600 Message-ID: <20251029061657.1456910-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251029061657.1456910-1-sjg@u-boot.org> References: <20251029061657.1456910-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 7WRHJPQJK633ECAPJJNH2LY5XXGPH3KK X-Message-ID-Hash: 7WRHJPQJK633ECAPJJNH2LY5XXGPH3KK X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 1/7] acpi: qfw: Add FPDT support for QEMU builds List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass QEMU creates ACPI tables but doesn't include FPDT (Firmware Performance Data Table). Add FPDT generation in qfw_acpi.c following the same pattern as BGRT. Move the acpi_write_fpdt() function from acpi_table.c to acpi_extra.c so that is available even when CONFIG_ACPIGEN is disabled. This allows QEMU x86_64 builds to provide firmware boot timing information to the operating system. Disable this for qemu-riscv64_smode_acpi as it is near the code-size limit. Co-developed-by: Claude Signed-off-by: Simon Glass --- drivers/qfw/qfw_acpi.c | 10 +++++ lib/acpi/acpi_extra.c | 92 ++++++++++++++++++++++++++++++++++++++++++ lib/acpi/acpi_table.c | 90 ----------------------------------------- 3 files changed, 102 insertions(+), 90 deletions(-) diff --git a/drivers/qfw/qfw_acpi.c b/drivers/qfw/qfw_acpi.c index 916a59be7fb..7f7dba73155 100644 --- a/drivers/qfw/qfw_acpi.c +++ b/drivers/qfw/qfw_acpi.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -256,6 +257,15 @@ out: return addr; } + if (!IS_ENABLED(CONFIG_TARGET_QEMU_VIRT)) { + ret = acpi_write_fpdt(ctx, + bootstage_get_time(BOOTSTAGE_ID_START_UBOOT_F)); + if (ret) { + printf("error: failed to write FPDT (err=%dE)\n", ret); + return addr; + } + } + return addr; } diff --git a/lib/acpi/acpi_extra.c b/lib/acpi/acpi_extra.c index 709f64305b5..09b8a251ca2 100644 --- a/lib/acpi/acpi_extra.c +++ b/lib/acpi/acpi_extra.c @@ -7,9 +7,11 @@ #define LOG_CATEGORY LOGC_ACPI +#include #include #include #include +#include #include #include @@ -87,3 +89,93 @@ int acpi_write_bgrt(struct acpi_ctx *ctx) return 0; } + +int acpi_write_fpdt(struct acpi_ctx *ctx, u64 uboot_start) +{ + struct acpi_fpdt *fpdt; + struct acpi_fpdt_boot *rec; + struct acpi_table_header *header; + u64 current_time; + int size; + + fpdt = ctx->current; + header = &fpdt->header; + + /* Calculate total size: FPDT header + boot performance record */ + size = sizeof(struct acpi_fpdt) + sizeof(struct acpi_fpdt_boot); + + memset(fpdt, '\0', size); + + /* Fill out FPDT header */ + acpi_fill_header(header, "FPDT"); + header->length = size; + header->revision = 1; /* ACPI 6.4+: 1 */ + + /* Add boot performance record right after FPDT header */ + rec = (struct acpi_fpdt_boot *)(fpdt + 1); + + /* Fill in record header */ + rec->hdr.type = FPDT_REC_BOOT; + rec->hdr.length = sizeof(struct acpi_fpdt_boot); + rec->hdr.revision = 2; /* FPDT Boot Performance Record revision */ + + /* Fill in timing data */ + current_time = timer_get_boot_us(); + rec->reset_end = uboot_start; + rec->loader_start = current_time; + rec->loader_exec = current_time; + rec->ebs_entry = current_time; + rec->ebs_exit = current_time; + + header->checksum = table_compute_checksum(fpdt, header->length); + + acpi_inc_align(ctx, size); + acpi_add_table(ctx, fpdt); + + return 0; +} + +struct acpi_fpdt_boot *acpi_get_fpdt_boot(void) +{ + struct acpi_table_header *header; + struct acpi_fpdt *fpdt; + + header = acpi_find_table("FPDT"); + if (!header) + return NULL; + + fpdt = (struct acpi_fpdt *)header; + return (struct acpi_fpdt_boot *)(fpdt + 1); +} + +int acpi_fix_fpdt_checksum(void) +{ + struct acpi_table_header *header; + + header = acpi_find_table("FPDT"); + if (!header) + return -ENOENT; + + header->checksum = 0; + header->checksum = table_compute_checksum(header, header->length); + + return 0; +} + +void acpi_final_fpdt(void) +{ + struct acpi_fpdt_boot *fpdt; + + if (IS_ENABLED(CONFIG_TARGET_QEMU_VIRT)) + return; + + fpdt = acpi_get_fpdt_boot(); + if (fpdt) { + u64 time; + + time = timer_get_boot_us(); + fpdt->ebs_entry = time; + fpdt->ebs_exit = time; + acpi_fix_fpdt_checksum(); + } +} diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index 99251176d09..94e6647b666 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -715,96 +715,6 @@ static int acpi_create_bgrt(struct acpi_ctx *ctx, ACPI_WRITER(6bgrt, "BGRT", acpi_create_bgrt, 0); #endif -int acpi_write_fpdt(struct acpi_ctx *ctx, u64 uboot_start) -{ - struct acpi_fpdt *fpdt; - struct acpi_fpdt_boot *rec; - struct acpi_table_header *header; - u64 current_time; - int size; - - fpdt = ctx->current; - header = &fpdt->header; - - /* Calculate total size: FPDT header + boot performance record */ - size = sizeof(struct acpi_fpdt) + sizeof(struct acpi_fpdt_boot); - - memset(fpdt, '\0', size); - - /* Fill out FPDT header */ - acpi_fill_header(header, "FPDT"); - header->length = size; - header->revision = acpi_get_table_revision(ACPITAB_FPDT); - - /* Add boot performance record right after FPDT header */ - rec = (struct acpi_fpdt_boot *)(fpdt + 1); - - /* Fill in record header */ - rec->hdr.type = FPDT_REC_BOOT; - rec->hdr.length = sizeof(struct acpi_fpdt_boot); - rec->hdr.revision = 2; /* FPDT Boot Performance Record revision */ - - /* Fill in timing data */ - current_time = timer_get_boot_us(); - rec->reset_end = uboot_start; - rec->loader_start = current_time; - rec->loader_exec = current_time; - rec->ebs_entry = current_time; - rec->ebs_exit = current_time; - - header->checksum = table_compute_checksum(fpdt, header->length); - - acpi_inc_align(ctx, size); - acpi_add_table(ctx, fpdt); - - return 0; -} - -struct acpi_fpdt_boot *acpi_get_fpdt_boot(void) -{ - struct acpi_table_header *header; - struct acpi_fpdt *fpdt; - - header = acpi_find_table("FPDT"); - if (!header) - return NULL; - - fpdt = (struct acpi_fpdt *)header; - return (struct acpi_fpdt_boot *)(fpdt + 1); -} - -int acpi_fix_fpdt_checksum(void) -{ - struct acpi_table_header *header; - - header = acpi_find_table("FPDT"); - if (!header) - return -ENOENT; - - header->checksum = 0; - header->checksum = table_compute_checksum(header, header->length); - - return 0; -} - -void acpi_final_fpdt(void) -{ - struct acpi_fpdt_boot *fpdt; - - if (IS_ENABLED(CONFIG_TARGET_QEMU_VIRT)) - return; - - fpdt = acpi_get_fpdt_boot(); - if (fpdt) { - u64 time; - - time = timer_get_boot_us(); - fpdt->ebs_entry = time; - fpdt->ebs_exit = time; - acpi_fix_fpdt_checksum(); - } -} - /* this board lacks the bootstage timer */ #ifndef CONFIG_TARGET_QEMU_VIRT