* [PATCH 1/6] resource: mark normal memory as supporting being uncacheable
@ 2025-06-16 7:16 Ahmad Fatoum
2025-06-16 7:16 ` [PATCH 2/6] lib: display_options: constify pointer to static size_human_readable buf Ahmad Fatoum
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2025-06-16 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The attributes report what the underlying memory is capable of,
so if we can configure it as WT/WC/WB, it's likely we can configure it
as uncached as well. This doesn't hold true for all architectures, but
it does for ARM, so add it to the MEMATTRS_NORMAL bitfield for now.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
include/linux/ioport.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 425928df3bfe..ceff1bb7e5ac 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -133,11 +133,11 @@ enum resource_memtype {
#define MEMATTR_RO 0x00020000 /* read-only */
#define MEMATTR_SP 0x00040000 /* specific-purpose */
-#define MEMATTRS_CACHEABLE (MEMATTR_WT | MEMATTR_WC | MEMATTR_WB)
-#define MEMATTRS_RW (MEMATTRS_CACHEABLE | MEMATTR_XP)
-#define MEMATTRS_RO (MEMATTRS_CACHEABLE | MEMATTR_XP | MEMATTR_RO)
-#define MEMATTRS_RX (MEMATTRS_CACHEABLE | MEMATTR_RO)
-#define MEMATTRS_RWX (MEMATTRS_CACHEABLE) /* TODO: remove all */
+#define MEMATTRS_NORMAL (MEMATTR_UC | MEMATTR_WT | MEMATTR_WC | MEMATTR_WB)
+#define MEMATTRS_RW (MEMATTRS_NORMAL | MEMATTR_XP)
+#define MEMATTRS_RO (MEMATTRS_NORMAL | MEMATTR_XP | MEMATTR_RO)
+#define MEMATTRS_RX (MEMATTRS_NORMAL | MEMATTR_RO)
+#define MEMATTRS_RWX (MEMATTRS_NORMAL) /* TODO: remove all */
#define MEMATTRS_RW_DEVICE (MEMATTR_UC | MEMATTR_XP)
#define MEMATTRS_FAULT (MEMATTR_UC | MEMATTR_XP | MEMATTR_RP | MEMATTR_RO)
--
2.39.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/6] lib: display_options: constify pointer to static size_human_readable buf
2025-06-16 7:16 [PATCH 1/6] resource: mark normal memory as supporting being uncacheable Ahmad Fatoum
@ 2025-06-16 7:16 ` Ahmad Fatoum
2025-06-16 7:16 ` [PATCH 3/6] commands: iomem: print human readable sizes by default Ahmad Fatoum
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2025-06-16 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The function returns a pointer to a statically allocated buffer
that's formatted with the string representation of the size.
It's a bad idea to modify it from the outside, so reflect that in the
type system.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
include/stdio.h | 2 +-
lib/display_options.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/stdio.h b/include/stdio.h
index 50688feff4e6..dcaed71dae05 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -97,7 +97,7 @@ static inline void ctrlc_handled(void)
#endif
-char *size_human_readable(unsigned long long size);
+const char *size_human_readable(unsigned long long size);
int readline(const char *prompt, char *buf, int len);
#if (IN_PROPER && !defined(CONFIG_CONSOLE_NONE)) || \
diff --git a/lib/display_options.c b/lib/display_options.c
index d392deef0a78..b6b913310603 100644
--- a/lib/display_options.c
+++ b/lib/display_options.c
@@ -21,7 +21,7 @@
*"as xxx KiB", "xxx.y KiB", "xxx MiB", "xxx.y MiB",
* xxx GiB, xxx.y GiB, etc as needed;
*/
-char *size_human_readable(unsigned long long size)
+const char *size_human_readable(unsigned long long size)
{
static char buf[30];
unsigned long m = 0, n;
--
2.39.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/6] commands: iomem: print human readable sizes by default
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 ` Ahmad Fatoum
2025-06-16 7:16 ` [PATCH 4/6] commands: iomemport: support showing info for particular argument Ahmad Fatoum
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2025-06-16 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We already print start and end in hexadecimal, so print a size of e.g.,
905.6 KiB doesn't lose any information when copy-pasting, but makes it
easier for quick sanity checks.
The newly introduced -v flag can be used to restore the old behavior.
For I/O ports, printing a size in bytes doesn't make sense, so we
exclude it via the FLAG_IOPORT flag.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
commands/iomemport.c | 51 +++++++++++++++++++++++++++++++++++++-------
1 file changed, 43 insertions(+), 8 deletions(-)
diff --git a/commands/iomemport.c b/commands/iomemport.c
index bbe41f571b48..2246868c2818 100644
--- a/commands/iomemport.c
+++ b/commands/iomemport.c
@@ -6,9 +6,17 @@
#include <asm/io.h>
#include <common.h>
#include <command.h>
+#include <getopt.h>
+#include <range.h>
-static void __print_resources(struct resource *res, int indent)
+#define FLAG_VERBOSE BIT(0)
+#define FLAG_IOPORT BIT(1)
+
+static void __print_resources(struct resource *res, int indent,
+ unsigned flags)
{
+ const char *size_str;
+ char buf[64];
struct resource *r;
resource_size_t size = resource_size(res);
int i;
@@ -16,24 +24,50 @@ static void __print_resources(struct resource *res, int indent)
for (i = 0; i < indent; i++)
printf(" ");
- printf("%pa - %pa (size %pa) %s%s\n",
- &res->start, &res->end, &size,
+ if (flags & (FLAG_VERBOSE | FLAG_IOPORT)) {
+ snprintf(buf, sizeof(buf), "%pa", &size);
+ size_str = buf;
+ } else {
+ 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);
list_for_each_entry(r, &res->children, sibling) {
- __print_resources(r, indent + 1);
+ __print_resources(r, indent + 1, flags);
}
}
-static void print_resources(struct resource *res)
+static void print_resources(struct resource *res, unsigned flags)
{
- __print_resources(res, 0);
+ __print_resources(res, 0, flags);
}
static int do_iomem(int argc, char *argv[])
{
- print_resources(&iomem_resource);
+ unsigned flags = 0;
+ int opt;
+
+ while((opt = getopt(argc, argv, "v")) > 0) {
+ switch(opt) {
+ case 'v':
+ flags |= FLAG_VERBOSE;
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ argv += optind;
+ argc -= optind;
+
+ if (argc > 0)
+ return COMMAND_ERROR_USAGE;
+
+ print_resources(&iomem_resource, flags);
return 0;
}
@@ -41,13 +75,14 @@ static int do_iomem(int argc, char *argv[])
BAREBOX_CMD_START(iomem)
.cmd = do_iomem,
BAREBOX_CMD_DESC("show IO memory usage")
+ BAREBOX_CMD_OPTS("[-v]")
BAREBOX_CMD_GROUP(CMD_GRP_INFO)
BAREBOX_CMD_END
#if IO_SPACE_LIMIT > 0
static int do_ioport(int argc, char *argv[])
{
- print_resources(&ioport_resource);
+ print_resources(&ioport_resource, FLAG_IOPORT);
return 0;
}
--
2.39.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 4/6] commands: iomemport: support showing info for particular argument
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
2025-06-16 7:16 ` [PATCH 5/6] commands: iomem: add support for printing type/attributes Ahmad Fatoum
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2025-06-16 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 5/6] commands: iomem: add support for printing type/attributes
2025-06-16 7:16 [PATCH 1/6] resource: mark normal memory as supporting being uncacheable Ahmad Fatoum
` (2 preceding siblings ...)
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
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
5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2025-06-16 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 6/6] efi: payload: iomem: populate resource type/attributes
2025-06-16 7:16 [PATCH 1/6] resource: mark normal memory as supporting being uncacheable Ahmad Fatoum
` (3 preceding siblings ...)
2025-06-16 7:16 ` [PATCH 5/6] commands: iomem: add support for printing type/attributes Ahmad Fatoum
@ 2025-06-16 7:16 ` Ahmad Fatoum
2025-06-17 7:13 ` [PATCH 1/6] resource: mark normal memory as supporting being uncacheable Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2025-06-16 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Now that the iomem command has support for printing type/attributes,
we don't need to print them for debugging during initcall.
Fill out the resources with the information and bump down the debug
print to verbose debug instead.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
efi/payload/iomem.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/efi/payload/iomem.c b/efi/payload/iomem.c
index 64f4b809e0c2..d58f95ca70a2 100644
--- a/efi/payload/iomem.c
+++ b/efi/payload/iomem.c
@@ -127,7 +127,7 @@ static int efi_parse_mmap(struct efi_memory_desc *desc, bool verbose)
fullname = xasprintf("%s@%llx", name, (u64)va_base);
- pr_debug("%s: (%pad+%pad)\n", fullname, &va_base, &va_size);
+ pr_vdebug("%s: (%pad+%pad)\n", fullname, &va_base, &va_size);
res = request_iomem_region(fullname, va_base, va_base + va_size - 1);
if (IS_ERR(res)) {
@@ -136,6 +136,7 @@ static int efi_parse_mmap(struct efi_memory_desc *desc, bool verbose)
}
res->flags |= flags;
+ resource_set_efi_memory_type_attrs(res, desc->type, desc->attrs);
out:
free(fullname);
--
2.39.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/6] resource: mark normal memory as supporting being uncacheable
2025-06-16 7:16 [PATCH 1/6] resource: mark normal memory as supporting being uncacheable Ahmad Fatoum
` (4 preceding siblings ...)
2025-06-16 7:16 ` [PATCH 6/6] efi: payload: iomem: populate resource type/attributes Ahmad Fatoum
@ 2025-06-17 7:13 ` Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2025-06-17 7:13 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Mon, 16 Jun 2025 09:16:29 +0200, Ahmad Fatoum wrote:
> The attributes report what the underlying memory is capable of,
> so if we can configure it as WT/WC/WB, it's likely we can configure it
> as uncached as well. This doesn't hold true for all architectures, but
> it does for ARM, so add it to the MEMATTRS_NORMAL bitfield for now.
>
>
Applied, thanks!
[1/6] resource: mark normal memory as supporting being uncacheable
https://git.pengutronix.de/cgit/barebox/commit/?id=1692b572c5b7 (link may not be stable)
[2/6] lib: display_options: constify pointer to static size_human_readable buf
https://git.pengutronix.de/cgit/barebox/commit/?id=811923c4da17 (link may not be stable)
[3/6] commands: iomem: print human readable sizes by default
https://git.pengutronix.de/cgit/barebox/commit/?id=d2edc81431bf (link may not be stable)
[4/6] commands: iomemport: support showing info for particular argument
https://git.pengutronix.de/cgit/barebox/commit/?id=fbc90b1e85bc (link may not be stable)
[5/6] commands: iomem: add support for printing type/attributes
https://git.pengutronix.de/cgit/barebox/commit/?id=f01559eed65f (link may not be stable)
[6/6] efi: payload: iomem: populate resource type/attributes
https://git.pengutronix.de/cgit/barebox/commit/?id=acdbfd557934 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-06-17 7:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox