From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 4/6] commands: iomemport: support showing info for particular argument
Date: Mon, 16 Jun 2025 09:16:32 +0200 [thread overview]
Message-ID: <20250616071634.811000-4-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250616071634.811000-1-a.fatoum@barebox.org>
Follow-up commit will start printing extra information on an address, so
prepare for that by allowing printout of information related to a
specific address.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
commands/iomemport.c | 54 ++++++++++++++++++++++++++++++++++++--------
1 file changed, 45 insertions(+), 9 deletions(-)
diff --git a/commands/iomemport.c b/commands/iomemport.c
index 2246868c2818..967566edd8d4 100644
--- a/commands/iomemport.c
+++ b/commands/iomemport.c
@@ -13,7 +13,7 @@
#define FLAG_IOPORT BIT(1)
static void __print_resources(struct resource *res, int indent,
- unsigned flags)
+ ulong *addr, unsigned flags)
{
const char *size_str;
char buf[64];
@@ -21,6 +21,9 @@ static void __print_resources(struct resource *res, int indent,
resource_size_t size = resource_size(res);
int i;
+ if (addr && !region_overlap_end(*addr, *addr, res->start, res->end))
+ return;
+
for (i = 0; i < indent; i++)
printf(" ");
@@ -37,19 +40,20 @@ static void __print_resources(struct resource *res, int indent,
res->name);
list_for_each_entry(r, &res->children, sibling) {
- __print_resources(r, indent + 1, flags);
+ __print_resources(r, indent + 1, addr, flags);
}
}
-static void print_resources(struct resource *res, unsigned flags)
+static void print_resources(struct resource *res, ulong *addr, unsigned flags)
{
- __print_resources(res, 0, flags);
+ __print_resources(res, 0, addr, flags);
}
static int do_iomem(int argc, char *argv[])
{
+ ulong addr, *arg = NULL;
unsigned flags = 0;
- int opt;
+ int opt, ret;
while((opt = getopt(argc, argv, "v")) > 0) {
switch(opt) {
@@ -64,25 +68,56 @@ static int do_iomem(int argc, char *argv[])
argv += optind;
argc -= optind;
- if (argc > 0)
+ if (argc > 1)
return COMMAND_ERROR_USAGE;
- print_resources(&iomem_resource, flags);
+ if (argv[0]) {
+ ret = kstrtoul(argv[0], 16, &addr);
+ if (ret)
+ return ret;
+ arg = &addr;
+ }
+
+ print_resources(&iomem_resource, arg, flags);
return 0;
}
+BAREBOX_CMD_HELP_START(iomem)
+BAREBOX_CMD_HELP_TEXT("Print barebox view of the physical address space.")
+BAREBOX_CMD_HELP_TEXT("An optional ADDRESS can be specified to get information")
+BAREBOX_CMD_HELP_TEXT("about its region in particular")
+BAREBOX_CMD_HELP_END
+
BAREBOX_CMD_START(iomem)
.cmd = do_iomem,
BAREBOX_CMD_DESC("show IO memory usage")
- BAREBOX_CMD_OPTS("[-v]")
+ BAREBOX_CMD_OPTS("[-v] [ADDRESS]")
BAREBOX_CMD_GROUP(CMD_GRP_INFO)
+ BAREBOX_CMD_HELP(cmd_iomem_help)
BAREBOX_CMD_END
#if IO_SPACE_LIMIT > 0
static int do_ioport(int argc, char *argv[])
{
- print_resources(&ioport_resource, FLAG_IOPORT);
+ ulong addr, *arg = NULL;
+ int ret;
+
+ /* No options supported */
+ argv += 1;
+ argc -= 1;
+
+ if (argc > 1)
+ return COMMAND_ERROR_USAGE;
+
+ if (argv[0]) {
+ ret = kstrtoul(argv[0], 16, &addr);
+ if (ret)
+ return ret;
+ arg = &addr;
+ }
+
+ print_resources(&ioport_resource, arg, FLAG_IOPORT);
return 0;
}
@@ -90,6 +125,7 @@ static int do_ioport(int argc, char *argv[])
BAREBOX_CMD_START(ioport)
.cmd = do_ioport,
BAREBOX_CMD_DESC("show IO port usage")
+ BAREBOX_CMD_OPTS("[PORT]")
BAREBOX_CMD_GROUP(CMD_GRP_INFO)
BAREBOX_CMD_END
#endif
--
2.39.5
next prev parent reply other threads:[~2025-06-16 7:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-16 7:16 [PATCH 1/6] resource: mark normal memory as supporting being uncacheable Ahmad Fatoum
2025-06-16 7:16 ` [PATCH 2/6] lib: display_options: constify pointer to static size_human_readable buf Ahmad Fatoum
2025-06-16 7:16 ` [PATCH 3/6] commands: iomem: print human readable sizes by default Ahmad Fatoum
2025-06-16 7:16 ` Ahmad Fatoum [this message]
2025-06-16 7:16 ` [PATCH 5/6] commands: iomem: add support for printing type/attributes Ahmad Fatoum
2025-06-16 7:16 ` [PATCH 6/6] efi: payload: iomem: populate resource type/attributes Ahmad Fatoum
2025-06-17 7:13 ` [PATCH 1/6] resource: mark normal memory as supporting being uncacheable 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=20250616071634.811000-4-a.fatoum@barebox.org \
--to=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