RISC-V: Add early ioremap support
authorAtish Patra <atish.patra@wdc.com>
Thu, 17 Sep 2020 22:37:11 +0000 (15:37 -0700)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Fri, 2 Oct 2020 21:31:03 +0000 (14:31 -0700)
UEFI uses early IO or memory mappings for runtime services before
normal ioremap() is usable. Add the necessary fixmap bindings and
pmd mappings for generic ioremap support to work.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Reviewed-by: Palmer Dabbelt <palmerdabbelt@google.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
arch/riscv/Kconfig
arch/riscv/include/asm/Kbuild
arch/riscv/include/asm/fixmap.h
arch/riscv/include/asm/io.h
arch/riscv/kernel/setup.c
arch/riscv/mm/init.c

index df18372861d8d22e3c0f6b8485c6128c65de733b..5e4ace64acbc10936d2b87aa0f96bd26b0bf460a 100644 (file)
@@ -37,6 +37,7 @@ config RISCV
        select GENERIC_ARCH_TOPOLOGY if SMP
        select GENERIC_ATOMIC64 if !64BIT
        select GENERIC_CLOCKEVENTS
+       select GENERIC_EARLY_IOREMAP
        select GENERIC_GETTIMEOFDAY if HAVE_GENERIC_VDSO
        select GENERIC_IOREMAP
        select GENERIC_IRQ_MULTI_HANDLER
index 3d9410bb4de02fed190dd9214c9dd4cf2ecdaa85..59dd7be550054fb785029616074579ab32dd8835 100644 (file)
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
+generic-y += early_ioremap.h
 generic-y += extable.h
 generic-y += flat.h
 generic-y += kvm_para.h
index 11613f38228ae7804e01e83c985353db3b526141..54cbf07fb4e9647a73d63cdc3c15595dc01e6b94 100644 (file)
@@ -27,6 +27,19 @@ enum fixed_addresses {
        FIX_TEXT_POKE1,
        FIX_TEXT_POKE0,
        FIX_EARLYCON_MEM_BASE,
+
+       __end_of_permanent_fixed_addresses,
+       /*
+        * Temporary boot-time mappings, used by early_ioremap(),
+        * before ioremap() is functional.
+        */
+#define NR_FIX_BTMAPS          (SZ_256K / PAGE_SIZE)
+#define FIX_BTMAPS_SLOTS       7
+#define TOTAL_FIX_BTMAPS       (NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS)
+
+       FIX_BTMAP_END = __end_of_permanent_fixed_addresses,
+       FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1,
+
        __end_of_fixed_addresses
 };
 
index 3835c3295dc51bbc90e7a9a21bcde1a148f1019e..c025a746a1486c1af7e3e860b355429610eeeb56 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/types.h>
 #include <linux/pgtable.h>
 #include <asm/mmiowb.h>
+#include <asm/early_ioremap.h>
 
 /*
  * MMIO access functions are separated out to break dependency cycles
index edea7ef884021fd2d2fa954d41539da4e7d70806..41ef96d0d97a62ac6026275486bde106e565a2cf 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/smp.h>
 
 #include <asm/cpu_ops.h>
+#include <asm/early_ioremap.h>
 #include <asm/setup.h>
 #include <asm/sections.h>
 #include <asm/sbi.h>
@@ -71,6 +72,7 @@ void __init setup_arch(char **cmdline_p)
 
        *cmdline_p = boot_command_line;
 
+       early_ioremap_setup();
        parse_early_param();
 
        setup_bootmem();
index 2b651f63f5c4b6522046fe8f8ef0452876e92998..b75ebe8e7a92d3efa917d91d414e37b882992ea7 100644 (file)
@@ -403,6 +403,9 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
        uintptr_t load_pa = (uintptr_t)(&_start);
        uintptr_t load_sz = (uintptr_t)(&_end) - load_pa;
        uintptr_t map_size = best_map_size(load_pa, MAX_EARLY_MAPPING_SIZE);
+#ifndef __PAGETABLE_PMD_FOLDED
+       pmd_t fix_bmap_spmd, fix_bmap_epmd;
+#endif
 
        va_pa_offset = PAGE_OFFSET - load_pa;
        pfn_base = PFN_DOWN(load_pa);
@@ -456,6 +459,36 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
                           pa + PGDIR_SIZE, PGDIR_SIZE, PAGE_KERNEL);
        dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PGDIR_SIZE - 1));
        dtb_early_pa = dtb_pa;
+
+       /*
+        * Bootime fixmap only can handle PMD_SIZE mapping. Thus, boot-ioremap
+        * range can not span multiple pmds.
+        */
+       BUILD_BUG_ON((__fix_to_virt(FIX_BTMAP_BEGIN) >> PMD_SHIFT)
+                    != (__fix_to_virt(FIX_BTMAP_END) >> PMD_SHIFT));
+
+#ifndef __PAGETABLE_PMD_FOLDED
+       /*
+        * Early ioremap fixmap is already created as it lies within first 2MB
+        * of fixmap region. We always map PMD_SIZE. Thus, both FIX_BTMAP_END
+        * FIX_BTMAP_BEGIN should lie in the same pmd. Verify that and warn
+        * the user if not.
+        */
+       fix_bmap_spmd = fixmap_pmd[pmd_index(__fix_to_virt(FIX_BTMAP_BEGIN))];
+       fix_bmap_epmd = fixmap_pmd[pmd_index(__fix_to_virt(FIX_BTMAP_END))];
+       if (pmd_val(fix_bmap_spmd) != pmd_val(fix_bmap_epmd)) {
+               WARN_ON(1);
+               pr_warn("fixmap btmap start [%08lx] != end [%08lx]\n",
+                       pmd_val(fix_bmap_spmd), pmd_val(fix_bmap_epmd));
+               pr_warn("fix_to_virt(FIX_BTMAP_BEGIN): %08lx\n",
+                       fix_to_virt(FIX_BTMAP_BEGIN));
+               pr_warn("fix_to_virt(FIX_BTMAP_END):   %08lx\n",
+                       fix_to_virt(FIX_BTMAP_END));
+
+               pr_warn("FIX_BTMAP_END:       %d\n", FIX_BTMAP_END);
+               pr_warn("FIX_BTMAP_BEGIN:     %d\n", FIX_BTMAP_BEGIN);
+       }
+#endif
 }
 
 static void __init setup_vm_final(void)