diff mbox series

[v4,27/27] lmb: add logic to print lmb flag strings

Message ID 20240826115940.3233167-28-sughosh.ganu@linaro.org
State Accepted
Commit f8ffc6f3cc4c6a760458255f5b344f86ee833bef
Headers show
Series Make LMB memory map global and persistent | expand

Commit Message

Sughosh Ganu Aug. 26, 2024, 11:59 a.m. UTC
Instead of printing the LMB flags as numerical values, print them as
strings. This makes it easier to understand what flags are associated
with the lmb region. Also make corresponding changes to the bdinfo
command's test code.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
Changes since V3:
* Put the tertiary expression in the puts() function call as suggested
  by Simon Glass.
* s/uin64_t/u64 in lmb_print_region_flags() as suggested by checkpatch.

 lib/lmb.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/lmb.c b/lib/lmb.c
index 9f1bb5ec7d..3ed570fb29 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -27,6 +27,19 @@  DECLARE_GLOBAL_DATA_PTR;
 
 static struct lmb lmb;
 
+static void lmb_print_region_flags(enum lmb_flags flags)
+{
+	u64 bitpos;
+	const char *flag_str[] = { "none", "no-map", "no-overwrite" };
+
+	do {
+		bitpos = flags ? fls(flags) - 1 : 0;
+		printf("%s", flag_str[bitpos]);
+		flags &= ~(1ull << bitpos);
+		puts(flags ? ", " : "\n");
+	} while (flags);
+}
+
 static void lmb_dump_region(struct alist *lmb_rgn_lst, char *name)
 {
 	struct lmb_region *rgn = lmb_rgn_lst->data;
@@ -42,8 +55,9 @@  static void lmb_dump_region(struct alist *lmb_rgn_lst, char *name)
 		end = base + size - 1;
 		flags = rgn[i].flags;
 
-		printf(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: %x\n",
-		       name, i, base, end, size, flags);
+		printf(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: ",
+		       name, i, base, end, size);
+		lmb_print_region_flags(flags);
 	}
 }