From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 5/6] commands: iomem: add support for printing type/attributes
Date: Mon, 16 Jun 2025 09:16:33 +0200 [thread overview]
Message-ID: <20250616071634.811000-5-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250616071634.811000-1-a.fatoum@barebox.org>
To make it easier to verify attributes, let's teach iomem to print the
newly added information. This intentionally only operates on the
resources, the mmuinfo command is what should print information actually
in the page tables.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
commands/iomemport.c | 3 ++
common/resource.c | 66 ++++++++++++++++++++++++++++++++++++++++++
include/linux/ioport.h | 3 ++
3 files changed, 72 insertions(+)
diff --git a/commands/iomemport.c b/commands/iomemport.c
index 967566edd8d4..bb546e4a3ad9 100644
--- a/commands/iomemport.c
+++ b/commands/iomemport.c
@@ -24,6 +24,9 @@ static void __print_resources(struct resource *res, int indent,
if (addr && !region_overlap_end(*addr, *addr, res->start, res->end))
return;
+ if ((flags & FLAG_VERBOSE) && !(flags & FLAG_IOPORT))
+ printf("%-58s", resource_typeattr_format(buf, sizeof(buf), res) ?: "");
+
for (i = 0; i < indent; i++)
printf(" ");
diff --git a/common/resource.c b/common/resource.c
index c233b106c17b..152f5a502a1e 100644
--- a/common/resource.c
+++ b/common/resource.c
@@ -183,3 +183,69 @@ struct resource_entry *resource_list_create_entry(struct resource *res,
return entry;
}
EXPORT_SYMBOL(resource_list_create_entry);
+
+static const char memory_type_name[][13] = {
+ "Reserved",
+ "Loader Code",
+ "Loader Data",
+ "Boot Code",
+ "Boot Data",
+ "Runtime Code",
+ "Runtime Data",
+ "Conventional",
+ "Unusable",
+ "ACPI Reclaim",
+ "ACPI Mem NVS",
+ "MMIO",
+ "MMIO Port",
+ "PAL Code",
+ "Persistent",
+ "Unaccepted",
+};
+
+const char *resource_typeattr_format(char *buf, size_t size,
+ const struct resource *res)
+{
+ char *pos;
+ int type_len;
+ u64 attr;
+
+ if (!(res->flags & IORESOURCE_TYPE_VALID))
+ return NULL;
+
+ pos = buf;
+ type_len = snprintf(pos, size, "[%-*s",
+ (int)(sizeof(memory_type_name[0]) - 1),
+ memory_type_name[res->type]);
+ if (type_len >= size)
+ return buf;
+
+ pos += type_len;
+ size -= type_len;
+
+ attr = res->attrs;
+ if (attr & ~(MEMATTR_UC | MEMATTR_WC | MEMATTR_WT |
+ MEMATTR_WB | MEMATTR_UCE | MEMATTR_RO |
+ MEMATTR_WP | MEMATTR_RP | MEMATTR_XP |
+ MEMATTR_NV | MEMATTR_SP | MEMATTR_MORE_RELIABLE)
+ )
+ snprintf(pos, size, "|attr=0x%08llx]",
+ (unsigned long long)attr);
+ else
+ snprintf(pos, size,
+ "|%3s|%2s|%2s|%2s|%2s|%2s|%2s|%2s|%3s|%2s|%2s|%2s|%2s]",
+ res->runtime ? "RUN" : "",
+ attr & MEMATTR_MORE_RELIABLE ? "MR" : "",
+ attr & MEMATTR_SP ? "SP" : "",
+ attr & MEMATTR_NV ? "NV" : "",
+ attr & MEMATTR_XP ? "XP" : "",
+ attr & MEMATTR_RP ? "RP" : "",
+ attr & MEMATTR_WP ? "WP" : "",
+ attr & MEMATTR_RO ? "RO" : "",
+ attr & MEMATTR_UCE ? "UCE" : "",
+ attr & MEMATTR_WB ? "WB" : "",
+ attr & MEMATTR_WT ? "WT" : "",
+ attr & MEMATTR_WC ? "WC" : "",
+ attr & MEMATTR_UC ? "UC" : "");
+ return buf;
+}
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index ceff1bb7e5ac..290f9feddcb9 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -212,6 +212,9 @@ int release_region(struct resource *res);
extern struct resource iomem_resource;
extern struct resource ioport_resource;
+const char *resource_typeattr_format(char *buf, size_t size,
+ const struct resource *res);
+
static inline void reserve_resource(struct resource *res)
{
res->type = MEMTYPE_RESERVED;
--
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 ` [PATCH 4/6] commands: iomemport: support showing info for particular argument Ahmad Fatoum
2025-06-16 7:16 ` Ahmad Fatoum [this message]
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-5-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