From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/6] commands: iomem: add support for printing gaps
Date: Thu, 11 Dec 2025 21:50:05 +0100 [thread overview]
Message-ID: <20251211205240.2836186-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20251211205240.2836186-1-a.fatoum@pengutronix.de>
With the new resource_iter support, it's easy to walk gaps between
resources as well, so wire this into the iomem command.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/iomemport.c | 41 ++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)
diff --git a/commands/iomemport.c b/commands/iomemport.c
index fe1273ba7451..c5b1ea8909e4 100644
--- a/commands/iomemport.c
+++ b/commands/iomemport.c
@@ -12,6 +12,7 @@
#define FLAG_VERBOSE BIT(0)
#define FLAG_IOPORT BIT(1)
#define FLAG_JSON BIT(2)
+#define FLAG_GAPS BIT(3)
static inline bool json_puts(const char *str, int flags)
{
@@ -26,12 +27,14 @@ static inline bool json_puts(const char *str, int flags)
static void __print_resources(struct resource *res, int indent,
ulong *addr, unsigned flags)
{
- const char *size_str;
+ const char *size_str, *name;
char buf[64];
- struct resource *r;
+ struct resource *gap, _gap;
resource_size_t size = resource_size(res);
int i;
+ gap = flags & FLAG_GAPS ? &_gap : NULL;
+
if (addr && !region_overlap_end_inclusive(*addr, *addr, res->start, res->end))
return;
@@ -41,11 +44,14 @@ static void __print_resources(struct resource *res, int indent,
for (i = 0; i < indent; i++)
printf(" ");
+ name = res->name ?: "";
+
if (flags & FLAG_JSON) {
printf("{ \"name\": \"%s\", \"start\": \"%pa\", "
- "\"end\": \"%pa\", \"reserved\": %s",
- res->name, &res->start, &res->end,
- is_reserved_resource(res) ? "true" : "false");
+ "\"end\": \"%pa\", \"reserved\": %s%s",
+ name, &res->start, &res->end,
+ is_reserved_resource(res) ? "true" : "false",
+ region_is_gap(res) ? ", \"free\": true" : "");
} else {
if (flags & (FLAG_VERBOSE | FLAG_IOPORT)) {
snprintf(buf, sizeof(buf), "%pa", &size);
@@ -54,19 +60,24 @@ static void __print_resources(struct resource *res, int indent,
size_str = size_human_readable(size);
}
- printf("%pa - %pa (size %9s) %s%s\n",
- &res->start, &res->end, size_str,
- is_reserved_resource(res) ? "[R] " : "",
- res->name);
+ printf("%pa - %pa (%s %9s) %s%s\n",
+ &res->start, &res->end, region_is_gap(res) ? "free" : "size",
+ size_str, is_reserved_resource(res) ? "[R] " : "", name);
}
if (!list_empty(&res->children)) {
+ struct resource *r = resource_iter_first(res, gap);
+
json_puts(", \"children\": [\n", flags);
- list_for_each_entry(r, &res->children, sibling) {
+
+ while (r) {
__print_resources(r, indent + 1, addr, flags);
- if (r->sibling.next != &res->children)
+
+ r = resource_iter_next(r, gap);
+ if (r)
json_puts(",\n", flags);
}
+
json_puts("]", flags);
}
@@ -85,7 +96,7 @@ static int do_iomem(int argc, char *argv[])
unsigned flags = 0;
int opt, ret;
- while((opt = getopt(argc, argv, "vj")) > 0) {
+ while((opt = getopt(argc, argv, "vjg")) > 0) {
switch(opt) {
case 'v':
flags |= FLAG_VERBOSE;
@@ -93,6 +104,9 @@ static int do_iomem(int argc, char *argv[])
case 'j':
flags |= FLAG_JSON;
break;
+ case 'g':
+ flags |= FLAG_GAPS;
+ break;
default:
return COMMAND_ERROR_USAGE;
}
@@ -124,12 +138,13 @@ BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT ("-v", "verbose output")
BAREBOX_CMD_HELP_OPT ("-j", "JSON output")
+BAREBOX_CMD_HELP_OPT ("-g", "include gaps")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(iomem)
.cmd = do_iomem,
BAREBOX_CMD_DESC("show IO memory usage")
- BAREBOX_CMD_OPTS("[-vj] [ADDRESS]")
+ BAREBOX_CMD_OPTS("[-vjg] [ADDRESS]")
BAREBOX_CMD_GROUP(CMD_GRP_INFO)
BAREBOX_CMD_HELP(cmd_iomem_help)
BAREBOX_CMD_END
--
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 ` Ahmad Fatoum [this message]
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 ` [PATCH 5/6] memory: add helpers for iterating over memory regions Ahmad Fatoum
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-4-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--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