riscv: add BUILTIN_DTB support for MMU-enabled targets
authorVitaly Wool <vitaly.wool@konsulko.com>
Fri, 15 Jan 2021 23:49:48 +0000 (01:49 +0200)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Fri, 19 Feb 2021 07:17:54 +0000 (23:17 -0800)
Sometimes, especially in a production system we may not want to
use a "smart bootloader" like u-boot to load kernel, ramdisk and
device tree from a filesystem on eMMC, but rather load the kernel
from a NAND partition and just run it as soon as we can, and in
this case it is convenient to have device tree compiled into the
kernel binary. Since this case is not limited to MMU-less systems,
let's support it for these which have MMU enabled too.

While at it, provide __dtb_start as a parameter to setup_vm() in
BUILTIN_DTB case, so we don't have to duplicate BUILTIN_DTB specific
processing in MMU-enabled and MMU-disabled versions of setup_vm().

Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
arch/riscv/Kconfig
arch/riscv/kernel/head.S
arch/riscv/mm/init.c

index c8d45da8edd931cca8bb294dcf86713b835b0e99..8eadd1cbd524ebd90cb92c8de5e3bd797296c5ca 100644 (file)
@@ -460,7 +460,6 @@ endmenu
 
 config BUILTIN_DTB
        def_bool n
-       depends on RISCV_M_MODE
        depends on OF
 
 menu "Power management options"
index 16e9941900c4d0c9a9acca6e4209d9c615711dee..f5a9bad86e5831890441e9c7c216d406664b2540 100644 (file)
@@ -260,7 +260,11 @@ clear_bss_done:
 
        /* Initialize page tables and relocate to virtual addresses */
        la sp, init_thread_union + THREAD_SIZE
+#ifdef CONFIG_BUILTIN_DTB
+       la a0, __dtb_start
+#else
        mv a0, s1
+#endif /* CONFIG_BUILTIN_DTB */
        call setup_vm
 #ifdef CONFIG_MMU
        la a0, early_pg_dir
index 30b61f2c6b8731a3fe04615ff24f91af7b159b08..45faad7c42919d0b492b806c39b2cf491f82edca 100644 (file)
@@ -192,10 +192,13 @@ void __init setup_bootmem(void)
 #endif /* CONFIG_BLK_DEV_INITRD */
 
        /*
-        * Avoid using early_init_fdt_reserve_self() since __pa() does
+        * If DTB is built in, no need to reserve its memblock.
+        * Otherwise, do reserve it but avoid using
+        * early_init_fdt_reserve_self() since __pa() does
         * not work for DTB pointers that are fixmap addresses
         */
-       memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va));
+       if (!IS_ENABLED(CONFIG_BUILTIN_DTB))
+               memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va));
 
        early_init_fdt_scan_reserved_mem();
        dma_contiguous_reserve(dma32_phys_limit);
@@ -499,6 +502,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
        /* Setup early PMD for DTB */
        create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA,
                           (uintptr_t)early_dtb_pmd, PGDIR_SIZE, PAGE_TABLE);
+#ifndef CONFIG_BUILTIN_DTB
        /* Create two consecutive PMD mappings for FDT early scan */
        pa = dtb_pa & ~(PMD_SIZE - 1);
        create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA,
@@ -506,7 +510,11 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
        create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA + PMD_SIZE,
                           pa + PMD_SIZE, PMD_SIZE, PAGE_KERNEL);
        dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PMD_SIZE - 1));
+#else /* CONFIG_BUILTIN_DTB */
+       dtb_early_va = __va(dtb_pa);
+#endif /* CONFIG_BUILTIN_DTB */
 #else
+#ifndef CONFIG_BUILTIN_DTB
        /* Create two consecutive PGD mappings for FDT early scan */
        pa = dtb_pa & ~(PGDIR_SIZE - 1);
        create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA,
@@ -514,6 +522,9 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
        create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA + PGDIR_SIZE,
                           pa + PGDIR_SIZE, PGDIR_SIZE, PAGE_KERNEL);
        dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PGDIR_SIZE - 1));
+#else /* CONFIG_BUILTIN_DTB */
+       dtb_early_va = __va(dtb_pa);
+#endif /* CONFIG_BUILTIN_DTB */
 #endif
        dtb_early_pa = dtb_pa;
 
@@ -604,11 +615,7 @@ static void __init setup_vm_final(void)
 #else
 asmlinkage void __init setup_vm(uintptr_t dtb_pa)
 {
-#ifdef CONFIG_BUILTIN_DTB
-       dtb_early_va = (void *) __dtb_start;
-#else
        dtb_early_va = (void *)dtb_pa;
-#endif
        dtb_early_pa = dtb_pa;
 }