From patchwork Sat Jan 10 20:28:33 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1447 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=1768076967; bh=KLlJpNa/2MD792wCIZYU7LzM6DMou+SUu7kU0fydkXg=; 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=FQK2anIGkvxavZEwi7GL9yiXACQfmKaZsOjPHnu3BG9U5Ms0XFq4p1W9Na9oJo37G WIT/Xep3mn5upM+PZJFfavT1re4rFl00RpN6QG3SGC+XcZDe+nc/u64bPK+fAUeMC1 Ig8tGgOCXMQsYrpHkKANBUwmdrdz8nrPu69m4PbBvfh4PI0vHPckQ7ilj9twjiT2Mw Xs6W0uLYA+ogP11vCdH8RqJy0OAo3mkS1xhJWo2eFWPclOPVE8kCmqMGfPY+r7KkcY NlHxvIPjl/vI8VDtChMoQaf6VCz5Cc1OCzXEEC5q4TdQAymFicWkNUyh4KwlAv12vV 0vgv2pGPavxUA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4962469291 for ; Sat, 10 Jan 2026 13:29:27 -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 4p2EXmm_kVKo for ; Sat, 10 Jan 2026 13:29:27 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768076967; bh=KLlJpNa/2MD792wCIZYU7LzM6DMou+SUu7kU0fydkXg=; 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=FQK2anIGkvxavZEwi7GL9yiXACQfmKaZsOjPHnu3BG9U5Ms0XFq4p1W9Na9oJo37G WIT/Xep3mn5upM+PZJFfavT1re4rFl00RpN6QG3SGC+XcZDe+nc/u64bPK+fAUeMC1 Ig8tGgOCXMQsYrpHkKANBUwmdrdz8nrPu69m4PbBvfh4PI0vHPckQ7ilj9twjiT2Mw Xs6W0uLYA+ogP11vCdH8RqJy0OAo3mkS1xhJWo2eFWPclOPVE8kCmqMGfPY+r7KkcY NlHxvIPjl/vI8VDtChMoQaf6VCz5Cc1OCzXEEC5q4TdQAymFicWkNUyh4KwlAv12vV 0vgv2pGPavxUA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3837169281 for ; Sat, 10 Jan 2026 13:29:27 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768076965; bh=EIxCMFFqKvBbAPr9Vfv30wvgOK2ZTrDEOQ8hDrYrqIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VI+pflx14fi5Zksjp3spGj+F7seYP/ZfZL1Zjl3ksvvhanOMYT2LlebkSC6xeaj5h JkSGM0rIoho2Qpk5yXRPYRYJYI34HZLpgx5omz8+F2nhShJ7QZu0j3SSnFd7j9UZa4 OgJ+4ma3PPNNWLqIxW3ZN9SuidxEtGUhQbShhGixKsR1hItkaWBjeQuKqLtFjbCnho t/4+Ob1bGFSnHEAe/r3z49IhaGTJ7ISedUWNJE0TAGAH4PpMA3fE32qs+4Pdb4lHk+ ri+GMiT3Qunpdk0nRzxHQQjA526M5ExP7uUfPJgmdCC1GDgv+P9N4qskW6zPSLDQrd oNaDhqFKrQCKg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6D95C69221; Sat, 10 Jan 2026 13:29:25 -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 UsTuXfVdaWMY; Sat, 10 Jan 2026 13:29:25 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768076961; bh=Rbe8Fly0Dj/UF6Z+KGejD78R+D4tRLRd7P2NUkB6bG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FoLKVJaGVPH4ATWsrJBm0Cv+ZU2JmrlOc/3rBEfCgzJeLKZgoyBY6hmoS8MzrmGms 5GBqE2s2qNwsCuiRBkdufKYfJc5kXpkJbofnh7+QPHuhu+WhNulhz/2twwaLOirTFn VoUnSALioYH9opcfyS4eyAMh2v5BmX99Jx571zQYEXQ8iaOBJpzC5XE7vsB405xC3+ 13XB8B2wureAKjruxtSoTRVv3aRMqZX3gEQHxyteGeyNFHKNAFcWd1fEXcenmmXyKU 6VL2YZSRXEcshMIoVFVePshyAFQC9t81sBaoSfdrY6pDlnFmyUOO+5ihnZmNt7CBKW csdoS8zpYZLoA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0E7A269186; Sat, 10 Jan 2026 13:29:21 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 10 Jan 2026 13:28:33 -0700 Message-ID: <20260110202906.187370-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260110202906.187370-1-sjg@u-boot.org> References: <20260110202906.187370-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: LEJDBFPWPBMRFLS7QXZGV2Q3GDKITBTZ X-Message-ID-Hash: LEJDBFPWPBMRFLS7QXZGV2Q3GDKITBTZ 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 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 01/26] lib: abuf: Add abuf_init_addr() helper 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 Add a helper function that combines abuf_init() and abuf_map_sysmem() into a single call. This simplifies code that needs to set up an abuf from a memory address. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- include/abuf.h | 12 ++++++++++++ lib/abuf.c | 6 ++++++ test/lib/abuf.c | 23 +++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/include/abuf.h b/include/abuf.h index 804ab0e3e57..42a80819d82 100644 --- a/include/abuf.h +++ b/include/abuf.h @@ -214,6 +214,18 @@ void abuf_init_const(struct abuf *abuf, const void *data, size_t size); */ void abuf_init_const_addr(struct abuf *abuf, ulong addr, size_t size); +/** + * abuf_init_addr() - Set up a new buffer at a given address + * + * This is similar to abuf_init_const_addr() but uses abuf_map_sysmem() + * internally. Note that the abuf is unallocated. + * + * @abuf: abuf to set up + * @addr: Address to use + * @size: Size of buffer + */ +void abuf_init_addr(struct abuf *abuf, ulong addr, size_t size); + /** * abuf_init_size() - Set up an allocated abuf * diff --git a/lib/abuf.c b/lib/abuf.c index 440f6a40023..f283f8e6e69 100644 --- a/lib/abuf.c +++ b/lib/abuf.c @@ -188,6 +188,12 @@ void abuf_init_const_addr(struct abuf *abuf, ulong addr, size_t size) { return abuf_init_const(abuf, map_sysmem(addr, size), size); } + +void abuf_init_addr(struct abuf *abuf, ulong addr, size_t size) +{ + abuf_init(abuf); + abuf_map_sysmem(abuf, addr, size); +} #endif void abuf_init_move(struct abuf *abuf, void *data, size_t size) diff --git a/test/lib/abuf.c b/test/lib/abuf.c index e97bb8b66bc..e6032998e94 100644 --- a/test/lib/abuf.c +++ b/test/lib/abuf.c @@ -91,6 +91,29 @@ static int lib_test_abuf_init_const_addr(struct unit_test_state *uts) } LIB_TEST(lib_test_abuf_init_const_addr, 0); +/* Test abuf_init_addr() */ +static int lib_test_abuf_init_addr(struct unit_test_state *uts) +{ + struct abuf buf; + ulong start; + void *ptr; + + start = ut_check_free(); + + ptr = map_sysmem(0x100, 0); + + abuf_init_addr(&buf, 0x100, 10); + ut_asserteq_ptr(ptr, buf.data); + ut_asserteq(10, buf.size); + ut_asserteq(false, buf.alloced); + + /* No memory should have been allocated */ + ut_assertok(ut_check_delta(start)); + + return 0; +} +LIB_TEST(lib_test_abuf_init_addr, 0); + /* Test abuf_map_sysmem() and abuf_addr() */ static int lib_test_abuf_map_sysmem(struct unit_test_state *uts) {