[PATCH 07/22] ARM: mmu: print map type as string

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Aug 6 05:36:59 PDT 2025


To make early debugging of the MMU easier, let's add support for
printing the MMU mapping type as a string.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/cpu/mmu-common.c | 14 ++++++++++++++
 arch/arm/cpu/mmu-common.h | 16 ++++++++++++++++
 arch/arm/cpu/mmu_32.c     |  2 +-
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/arch/arm/cpu/mmu-common.c b/arch/arm/cpu/mmu-common.c
index 2e61dc36b7cc..1770c56b6eea 100644
--- a/arch/arm/cpu/mmu-common.c
+++ b/arch/arm/cpu/mmu-common.c
@@ -16,6 +16,20 @@
 #include "mmu-common.h"
 #include <efi/efi-mode.h>
 
+const char *map_type_tostr(maptype_t map_type)
+{
+	switch (map_type) {
+	case ARCH_MAP_CACHED_RWX:	return "RWX";
+	case ARCH_MAP_CACHED_RO:	return "RO";
+	case MAP_CACHED:		return "CACHED";
+	case MAP_UNCACHED:		return "UNCACHED";
+	case MAP_CODE:			return "CODE";
+	case MAP_WRITECOMBINE:		return "WRITECOMBINE";
+	case MAP_FAULT:			return "FAULT";
+	default:			return "<unknown>";
+	}
+}
+
 void arch_sync_dma_for_cpu(void *vaddr, size_t size,
 			   enum dma_data_direction dir)
 {
diff --git a/arch/arm/cpu/mmu-common.h b/arch/arm/cpu/mmu-common.h
index e9005dfae766..01d081db426e 100644
--- a/arch/arm/cpu/mmu-common.h
+++ b/arch/arm/cpu/mmu-common.h
@@ -57,4 +57,20 @@ static inline size_t resource_count_pages(const struct resource *res)
 	return ALIGN(resource_size(res), SZ_4K);
 }
 
+const char *map_type_tostr(maptype_t map_type);
+
+static inline void __pr_debug_remap(const char *func, ulong virt_addr, ulong phys_addr,
+				  size_t size, maptype_t map_type)
+{
+	if (phys_addr == virt_addr)
+		pr_debug("%s: 0x%08lx+0x%zx type %s\n",	func,
+			 virt_addr, size, map_type_tostr(map_type));
+	else
+		pr_debug("%s: 0x%08lx+0x%zx -> 0x%08lx type %s\n", func,
+			 virt_addr, size, phys_addr, map_type_tostr(map_type));
+}
+
+#define pr_debug_remap(virt_addr, phys_addr, size, map_type)	\
+	__pr_debug_remap(__func__, virt_addr, phys_addr, size, map_type)
+
 #endif
diff --git a/arch/arm/cpu/mmu_32.c b/arch/arm/cpu/mmu_32.c
index e631b741f107..4b7f370edaea 100644
--- a/arch/arm/cpu/mmu_32.c
+++ b/arch/arm/cpu/mmu_32.c
@@ -278,7 +278,7 @@ static void __arch_remap_range(void *_virt_addr, phys_addr_t phys_addr, size_t s
 	pte_flags = get_pte_flags(map_type);
 	pmd_flags = pte_flags_to_pmd(pte_flags);
 
-	pr_debug("%s: 0x%08x 0x%08x type %d\n", __func__, virt_addr, size, map_type);
+	pr_debug_remap(virt_addr, phys_addr, size, map_type);
 
 	size = PAGE_ALIGN(size);
 	if (!size)
-- 
2.39.5




More information about the barebox mailing list