]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
arm: armv8: mmu: add mmu_unmap_reserved_mem
authorAnshul Dalal <anshuld@ti.com>
Fri, 17 Oct 2025 13:15:29 +0000 (18:45 +0530)
committerTom Rini <trini@konsulko.com>
Wed, 22 Oct 2025 18:05:52 +0000 (12:05 -0600)
For armv8, U-Boot uses a static map defined as 'mem_map' for configuring
the MMU's page tables, done by mmu_setup.

Though this works well for simpler platforms, it makes creating runtime
carveouts by modifying the static array at runtime exceedingly complex
like in mach-snapdragon/board.c.

Creation of such carveouts are much better handled by APIs such as
mmu_change_region_attr once the page tables are configured. Usually such
carveouts are configured via the device-tree's reserved-memory node
which provides the address and size for the carveout.

Therefore this patch adds mmu_unmap_reserved_mem which acts as a wrapper
over mmu_change_region_attr, helping unmap a reserved-memory region.

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Anshul Dalal <anshuld@ti.com>
Tested-by: Wadim Egorov <w.egorov@phytec.de>
arch/arm/cpu/armv8/cache_v8.c
arch/arm/include/asm/armv8/mmu.h

index 9b3c37dae8207d0f8087b55f3ac8f4ca9419a56d..672ec16d4834be501d5bfa343af9537aa9285252 100644 (file)
@@ -86,6 +86,32 @@ int mem_map_from_dram_banks(unsigned int index, unsigned int len, u64 attrs)
 
        return 0;
 }
+
+int mmu_unmap_reserved_mem(const char *name, bool check_nomap)
+{
+       void *fdt = (void *)gd->fdt_blob;
+       char node_path[128];
+       fdt_addr_t addr;
+       fdt_size_t size;
+       int ret;
+
+       snprintf(node_path, sizeof(node_path), "/reserved-memory/%s", name);
+       ret = fdt_path_offset(fdt, node_path);
+       if (ret < 0)
+               return ret;
+
+       if (check_nomap && !fdtdec_get_bool(fdt, ret, "no-map"))
+               return -EINVAL;
+
+       addr = fdtdec_get_addr_size(fdt, ret, "reg", &size);
+       if (addr == FDT_ADDR_T_NONE)
+               return -1;
+
+       mmu_change_region_attr_nobreak(addr, size, PTE_TYPE_FAULT);
+
+       return 0;
+}
+
 u64 get_tcr(u64 *pips, u64 *pva_bits)
 {
        int el = get_effective_el();
index 6e7a33668446cc0ae33d43db55d9c46998fd55c3..8aa5f9721c4a98a9d992e5e7cf152cde82202be0 100644 (file)
@@ -207,6 +207,15 @@ void setup_pgtables(void);
  */
 int mem_map_from_dram_banks(unsigned int index, unsigned int len, u64 attrs);
 
+/**
+ * mmu_unmap_reserved_mem() - Unmaps a reserved-memory node as PTE_TYPE_FAULT
+ * once MMU is configured by mmu_setup.
+ *
+ * @name: The name of the node under "/reserved-memory/" path
+ * @check_nomap: Check if the node is marked "no-map" before unmapping it
+ */
+int mmu_unmap_reserved_mem(const char *name, bool check_nomap);
+
 u64 get_tcr(u64 *pips, u64 *pva_bits);
 
 /**