From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>,
Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 5/6] memory: add helpers for iterating over memory regions
Date: Thu, 11 Dec 2025 21:50:07 +0100 [thread overview]
Message-ID: <20251211205240.2836186-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20251211205240.2836186-1-a.fatoum@pengutronix.de>
From: Ahmad Fatoum <a.fatoum@barebox.org>
Now that we have the resource_iter_* functions, add helpers for
conveniently traversing requested regions and the gaps between them.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/linux/ioport.h | 18 ++++++++++++++++++
include/memory.h | 6 ++++++
2 files changed, 24 insertions(+)
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 1b5dfdcb373d..1d8686d51e81 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -272,5 +272,23 @@ struct resource *resource_iter_last(struct resource *current, struct resource *g
struct resource *resource_iter_prev(struct resource *current, struct resource *gap);
struct resource *resource_iter_next(struct resource *current, struct resource *gap);
+/**
+ * for_each_resource_region - Iterate over child resources and gaps between them
+ * @parent: parent resource
+ * @region: pointer to child resource or gap
+ */
+#define for_each_resource_region(parent, region) \
+ for (struct resource gap, *region = resource_iter_first((parent), &gap); \
+ region; region = resource_iter_next(region, &gap))
+
+/**
+ * for_each_resource_region_reverse - Reverse iterate over child resources and gaps between them
+ * @parent: parent resource
+ * @region: pointer to child resource or gap
+ */
+#define for_each_resource_region_reverse(parent, region) \
+ for (struct resource gap, *region = resource_iter_last((parent), &gap); \
+ region; region = resource_iter_prev(region, &gap))
+
#endif /* __ASSEMBLY__ */
#endif /* _LINUX_IOPORT_H */
diff --git a/include/memory.h b/include/memory.h
index dea76dd2b1f7..65614b97ec8b 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -30,6 +30,12 @@ int barebox_add_memory_bank(const char *name, resource_size_t start,
list_for_each_entry(rsv, &(mem)->res->children, sibling) \
if (is_reserved_resource(rsv))
+#define for_each_memory_bank_region(bank, region) \
+ for_each_resource_region((bank)->res, region)
+
+#define for_each_memory_bank_region_reverse(bank, region) \
+ for_each_resource_region_reverse((bank)->res, region)
+
struct resource *__request_sdram_region(const char *name,
resource_size_t start, resource_size_t size);
--
2.47.3
next prev parent reply other threads:[~2025-12-11 20:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-11 20:50 [PATCH 0/6] resource: add support for walking resource gaps Ahmad Fatoum
2025-12-11 20:50 ` [PATCH 1/6] resource: implement resource walker Ahmad Fatoum
2025-12-11 20:50 ` [PATCH 2/6] test: self: implement resource walker selftest Ahmad Fatoum
2025-12-11 20:50 ` [PATCH 3/6] commands: iomem: add support for printing gaps Ahmad Fatoum
2025-12-11 20:50 ` [PATCH 4/6] test: py: add test for valid JSON output from iomem/clk_dump Ahmad Fatoum
2025-12-11 20:50 ` Ahmad Fatoum [this message]
2025-12-11 20:50 ` [PATCH 6/6] resource: implement release_region_range Ahmad Fatoum
2025-12-15 9:29 ` [PATCH 0/6] resource: add support for walking resource gaps Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251211205240.2836186-6-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox