From patchwork Thu Feb 12 00:13:55 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1827 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=1770855281; bh=u5pfBV2LHRkGxQJ7lHHsWzuZUCsD2RT6rMfmQ0mBkG0=; 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=XtBPpfGYLzkzFCR90X8LKOWZmwJRMHWQzYkNxOLJyn9HtBnzQ6Ruh68cd0diDpwZn RUxIj3gGzfA36Uc2ENOIxlccaIN0a56TcfgMYMsjQxhSHF53AVWEZGEsYjjxCXoLNi Aiv0n67DKtvG9efpNkGqJrRESncX5V6DDWqgZZP6RzcwjeHUrhGXVhh4mqgl4EZQH/ eZx0B0QzZNCMp0zO5XNeq9tWGnn52g+QPhNRL37vdMiBRFCItHDnZU79ZCmguv8xGc a7Na+CiEVNAWJz/WwxOaLHv7A2DZq1Ds1tVhkFU3PMRDN4VmbTlKVQ/2fYGqRcZZLS kugf8txW+mMZw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6CE73699C6 for ; Wed, 11 Feb 2026 17:14:41 -0700 (MST) 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 o51DLtfBmEHT for ; Wed, 11 Feb 2026 17:14:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770855281; bh=u5pfBV2LHRkGxQJ7lHHsWzuZUCsD2RT6rMfmQ0mBkG0=; 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=XtBPpfGYLzkzFCR90X8LKOWZmwJRMHWQzYkNxOLJyn9HtBnzQ6Ruh68cd0diDpwZn RUxIj3gGzfA36Uc2ENOIxlccaIN0a56TcfgMYMsjQxhSHF53AVWEZGEsYjjxCXoLNi Aiv0n67DKtvG9efpNkGqJrRESncX5V6DDWqgZZP6RzcwjeHUrhGXVhh4mqgl4EZQH/ eZx0B0QzZNCMp0zO5XNeq9tWGnn52g+QPhNRL37vdMiBRFCItHDnZU79ZCmguv8xGc a7Na+CiEVNAWJz/WwxOaLHv7A2DZq1Ds1tVhkFU3PMRDN4VmbTlKVQ/2fYGqRcZZLS kugf8txW+mMZw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5B4B169A88 for ; Wed, 11 Feb 2026 17:14:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770855279; bh=j5av7G9nUvFdXJArK3K4xaadTO65BbFjRwaQgWWueCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ssKfx9mB4H5P0Vvcf6p7XXhkmPOH5LK5G2lFqPmWjJDHhaAmf8+pvBVz7Ehc3zrko TmhyaTWS3/4gNhylJ531U2263YZSLUmpZ1dWSuN9VUETy64wuANQXE7tM8tLbUtEye mTVnzDQZWaIhyvQh02UAoAf/ArQZ93HG7PNdqMCj/XqxJWpkFjt764H8ipYrK2bheo 0sjsxyzoRb9qYnmzcKAEOoqpVmWd4V6N+zw7s/++WecaIkM8kxMW1iy2gXuPBcMeCl Ua6mosJ5tTEA5YrQpELLLLnsHGWJy3+U1gpkhk1Rvl3sb8FpBZ0/p+wCs37aYWB3vy MHb3Yn0Sx2H4Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3234A69A88; Wed, 11 Feb 2026 17:14:39 -0700 (MST) 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 BKaBZiYWeNs0; Wed, 11 Feb 2026 17:14:39 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770855271; bh=sPln7iOM6rbfFCUlntvAW9GC1UkXJcZ/1agwhDLuC+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cUoDWlgl55fdB/qlm1N20chLTdCbpC/kG35SWIiJYdzfAktBHBnctUy3wFL8LQL34 AoZfV4zRw140bUr1B6YkaYJ+c16WyQWr7uQ2rM/HFHzDtfIOENpCNqdg3d9dqljsTE /JgIqUlb4utKU0e9tfeRZt7YXJGHdIpvn0a14Vr4nI9idyQwp5ZCHGRKxCAAcNrQGO w9KqP8tuN0rsCSa4QuOpq0R8ta5J7Y6C/fQalvUkgNfq9f4cXMZg1YW74NuU9xqSHm 5HvMAbHkxKuGvTpL/5hY5t1AOC25rGPD83rveHtiAFUhuR22cEivb0ay7Pvzn5D62E yCoQpv+GnvJew== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 6BD77699C6; Wed, 11 Feb 2026 17:14:31 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 11 Feb 2026 17:13:55 -0700 Message-ID: <20260212001410.1919749-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260212001410.1919749-1-sjg@u-boot.org> References: <20260212001410.1919749-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: UK2TL5NF4GIHDHWIVXXOCASXZC3DMKZH X-Message-ID-Hash: UK2TL5NF4GIHDHWIVXXOCASXZC3DMKZH 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: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 6" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 04/15] riscv: timer: Read timebase frequency from the firmware FDT 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 The RISC-V timer driver reads the clock rate from /cpus/timebase-frequency in U-Boot's own device tree. For EFI applications this property may not be present, since the embedded DTB is minimal. Add a fallback that reads the timebase frequency from the firmware- provided FDT, which is available via the EFI configuration tables. To support this, scan for EFI_FDT_GUID in scan_tables() and store the address via a new gd_set_firmware_fdt_addr() accessor. Co-developed-by: Claude Opus 4.6 Signed-off-by: Simon Glass --- drivers/timer/riscv_timer.c | 13 +++++++++++++ include/asm-generic/global_data.h | 8 ++++++++ lib/efi_client/efi_app.c | 3 +++ 3 files changed, 24 insertions(+) diff --git a/drivers/timer/riscv_timer.c b/drivers/timer/riscv_timer.c index 1f4980ceb38..ca28d1297d7 100644 --- a/drivers/timer/riscv_timer.c +++ b/drivers/timer/riscv_timer.c @@ -15,8 +15,12 @@ #include #include #include +#include #include #include +#include + +DECLARE_GLOBAL_DATA_PTR; static u64 notrace riscv_timer_get_count(struct udevice *dev) { @@ -89,6 +93,15 @@ static int riscv_timer_probe(struct udevice *dev) "/cpus", "timebase-frequency", 0); } + /* For EFI apps, try the firmware-provided FDT */ + if (!rate && IS_ENABLED(CONFIG_EFI_APP) && + gd_firmware_fdt_addr()) { + void *fw_fdt = map_sysmem(gd_firmware_fdt_addr(), 0); + + rate = fdt_getprop_u32_default(fw_fdt, "/cpus", + "timebase-frequency", 0); + } + uc_priv->clock_rate = rate; /* With rate==0, timer uclass post_probe might later fail with -EINVAL. diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index b17a2e4650b..86204e372aa 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -563,6 +563,14 @@ static_assert(sizeof(struct global_data) == GD_SIZE); #define gd_set_smbios_start(addr) #endif +#ifdef CONFIG_RISCV +#define gd_firmware_fdt_addr() gd->arch.firmware_fdt_addr +#define gd_set_firmware_fdt_addr(addr) gd->arch.firmware_fdt_addr = addr +#else +#define gd_firmware_fdt_addr() 0UL +#define gd_set_firmware_fdt_addr(addr) +#endif + #if CONFIG_IS_ENABLED(MULTI_DTB_FIT) #define gd_multi_dtb_fit() gd->multi_dtb_fit #define gd_set_multi_dtb_fit(_dtb) gd->multi_dtb_fit = _dtb diff --git a/lib/efi_client/efi_app.c b/lib/efi_client/efi_app.c index 178571d9970..d36ed959f95 100644 --- a/lib/efi_client/efi_app.c +++ b/lib/efi_client/efi_app.c @@ -172,6 +172,7 @@ static void scan_tables(struct efi_system_table *sys_table) efi_guid_t acpi = EFI_ACPI_TABLE_GUID; efi_guid_t smbios = SMBIOS_TABLE_GUID; efi_guid_t smbios3 = SMBIOS3_TABLE_GUID; + efi_guid_t fdt = EFI_FDT_GUID; uint i; for (i = 0; i < sys_table->nr_tables; i++) { @@ -182,6 +183,8 @@ static void scan_tables(struct efi_system_table *sys_table) else if (!memcmp(&tab->guid, &smbios, sizeof(efi_guid_t)) || !memcmp(&tab->guid, &smbios3, sizeof(efi_guid_t))) gd_set_smbios_start(map_to_sysmem(tab->table)); + else if (!memcmp(&tab->guid, &fdt, sizeof(efi_guid_t))) + gd_set_firmware_fdt_addr((ulong)tab->table); } }