[PATCH v2 04/33] abuf: Provide a way to get the buffer address

Simon Glass sjg at chromium.org
Mon Jan 6 15:32:00 CET 2025


In many cases it is useful to get the address of a buffer, e.g. when
booting from it. Add a function to handle this.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v1)

 include/abuf.h  | 8 ++++++++
 lib/abuf.c      | 6 ++++++
 test/lib/abuf.c | 4 +++-
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/include/abuf.h b/include/abuf.h
index be98ec78c86..76e314b9a47 100644
--- a/include/abuf.h
+++ b/include/abuf.h
@@ -42,6 +42,14 @@ static inline size_t abuf_size(const struct abuf *abuf)
 	return abuf->size;
 }
 
+/**
+ * abuf_addr() - Get the address of a buffer's data
+ *
+ * @abuf: Buffer to check
+ * Return: address of buffer
+ */
+ulong abuf_addr(const struct abuf *abuf);
+
 /**
  * abuf_set() - set the (unallocated) data in a buffer
  *
diff --git a/lib/abuf.c b/lib/abuf.c
index 937c3df351e..8156177c773 100644
--- a/lib/abuf.c
+++ b/lib/abuf.c
@@ -26,6 +26,12 @@ void abuf_map_sysmem(struct abuf *abuf, ulong addr, size_t size)
 {
 	abuf_set(abuf, map_sysmem(addr, size), size);
 }
+
+ulong abuf_addr(const struct abuf *abuf)
+{
+	return map_to_sysmem(abuf->data);
+}
+
 #else
 /* copied from lib/string.c for convenience */
 static char *memdup(const void *src, size_t len)
diff --git a/test/lib/abuf.c b/test/lib/abuf.c
index 7c0481ab610..5d61f9261c6 100644
--- a/test/lib/abuf.c
+++ b/test/lib/abuf.c
@@ -46,7 +46,7 @@ static int lib_test_abuf_set(struct unit_test_state *uts)
 }
 LIB_TEST(lib_test_abuf_set, 0);
 
-/* Test abuf_map_sysmem() */
+/* Test abuf_map_sysmem() and abuf_addr() */
 static int lib_test_abuf_map_sysmem(struct unit_test_state *uts)
 {
 	struct abuf buf;
@@ -60,6 +60,8 @@ static int lib_test_abuf_map_sysmem(struct unit_test_state *uts)
 	ut_asserteq(TEST_DATA_LEN, buf.size);
 	ut_asserteq(false, buf.alloced);
 
+	ut_asserteq(addr, abuf_addr(&buf));
+
 	return 0;
 }
 LIB_TEST(lib_test_abuf_map_sysmem, 0);
-- 
2.34.1



More information about the U-Boot mailing list