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.fat...@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