arm64: Factor out fixmap initialization from ioremap
authorLaura Abbott <lauraa@codeaurora.org>
Fri, 21 Nov 2014 21:50:42 +0000 (21:50 +0000)
committerWill Deacon <will.deacon@arm.com>
Tue, 25 Nov 2014 15:56:45 +0000 (15:56 +0000)
The fixmap API was originally added for arm64 for
early_ioremap purposes. It can be used for other purposes too
so move the initialization from ioremap to somewhere more
generic. This makes it obvious where the fixmap is being set
up and allows for a cleaner implementation of __set_fixmap.

Reviewed-by: Kees Cook <keescook@chromium.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Tested-by: Mark Rutland <mark.rutland@arm.com>
Tested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
arch/arm64/include/asm/fixmap.h
arch/arm64/kernel/setup.c
arch/arm64/mm/ioremap.c
arch/arm64/mm/mmu.c

index 5f7bfe6df723bb08ef5d20cc9deb196dab8a3811..db26a2f2b7a7486ffb690d234aae647b5295189e 100644 (file)
@@ -56,10 +56,11 @@ enum fixed_addresses {
 
 #define FIXMAP_PAGE_IO     __pgprot(PROT_DEVICE_nGnRE)
 
-extern void __early_set_fixmap(enum fixed_addresses idx,
-                              phys_addr_t phys, pgprot_t flags);
+void __init early_fixmap_init(void);
 
-#define __set_fixmap __early_set_fixmap
+#define __early_set_fixmap __set_fixmap
+
+extern void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot);
 
 #include <asm-generic/fixmap.h>
 
index c8629eb07ba65b494a30f064eea59e794b282219..1de0e8a895eeb6026fc959877c41103b397261b4 100644 (file)
@@ -384,6 +384,7 @@ void __init setup_arch(char **cmdline_p)
 
        *cmdline_p = boot_command_line;
 
+       early_fixmap_init();
        early_ioremap_init();
 
        parse_early_param();
index 4a07630a66165e9948ccffaaf888cdd21ddb2a8c..cbb99c8f1e04368f0da27e11868df06b5cfdea70 100644 (file)
@@ -103,97 +103,10 @@ void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size)
 }
 EXPORT_SYMBOL(ioremap_cache);
 
-static pte_t bm_pte[PTRS_PER_PTE] __page_aligned_bss;
-#if CONFIG_ARM64_PGTABLE_LEVELS > 2
-static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss;
-#endif
-#if CONFIG_ARM64_PGTABLE_LEVELS > 3
-static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss;
-#endif
-
-static inline pud_t * __init early_ioremap_pud(unsigned long addr)
-{
-       pgd_t *pgd;
-
-       pgd = pgd_offset_k(addr);
-       BUG_ON(pgd_none(*pgd) || pgd_bad(*pgd));
-
-       return pud_offset(pgd, addr);
-}
-
-static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
-{
-       pud_t *pud = early_ioremap_pud(addr);
-
-       BUG_ON(pud_none(*pud) || pud_bad(*pud));
-
-       return pmd_offset(pud, addr);
-}
-
-static inline pte_t * __init early_ioremap_pte(unsigned long addr)
-{
-       pmd_t *pmd = early_ioremap_pmd(addr);
-
-       BUG_ON(pmd_none(*pmd) || pmd_bad(*pmd));
-
-       return pte_offset_kernel(pmd, addr);
-}
-
+/*
+ * Must be called after early_fixmap_init
+ */
 void __init early_ioremap_init(void)
 {
-       pgd_t *pgd;
-       pud_t *pud;
-       pmd_t *pmd;
-       unsigned long addr = fix_to_virt(FIX_BTMAP_BEGIN);
-
-       pgd = pgd_offset_k(addr);
-       pgd_populate(&init_mm, pgd, bm_pud);
-       pud = pud_offset(pgd, addr);
-       pud_populate(&init_mm, pud, bm_pmd);
-       pmd = pmd_offset(pud, addr);
-       pmd_populate_kernel(&init_mm, pmd, bm_pte);
-
-       /*
-        * The boot-ioremap range spans multiple pmds, for which
-        * we are not prepared:
-        */
-       BUILD_BUG_ON((__fix_to_virt(FIX_BTMAP_BEGIN) >> PMD_SHIFT)
-                    != (__fix_to_virt(FIX_BTMAP_END) >> PMD_SHIFT));
-
-       if (pmd != early_ioremap_pmd(fix_to_virt(FIX_BTMAP_END))) {
-               WARN_ON(1);
-               pr_warn("pmd %p != %p\n",
-                       pmd, early_ioremap_pmd(fix_to_virt(FIX_BTMAP_END)));
-               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);
-       }
-
        early_ioremap_setup();
 }
-
-void __init __early_set_fixmap(enum fixed_addresses idx,
-                              phys_addr_t phys, pgprot_t flags)
-{
-       unsigned long addr = __fix_to_virt(idx);
-       pte_t *pte;
-
-       if (idx >= __end_of_fixed_addresses) {
-               BUG();
-               return;
-       }
-
-       pte = early_ioremap_pte(addr);
-
-       if (pgprot_val(flags))
-               set_pte(pte, pfn_pte(phys >> PAGE_SHIFT, flags));
-       else {
-               pte_clear(&init_mm, addr, pte);
-               flush_tlb_kernel_range(addr, addr+PAGE_SIZE);
-       }
-}
index f4f8b500f74c634ce62d36f25259e26c7826d2b7..6032f3e3056a6c69899b06ee4c86cc22aa985893 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/io.h>
 
 #include <asm/cputype.h>
+#include <asm/fixmap.h>
 #include <asm/sections.h>
 #include <asm/setup.h>
 #include <asm/sizes.h>
@@ -463,3 +464,96 @@ void vmemmap_free(unsigned long start, unsigned long end)
 {
 }
 #endif /* CONFIG_SPARSEMEM_VMEMMAP */
+
+static pte_t bm_pte[PTRS_PER_PTE] __page_aligned_bss;
+#if CONFIG_ARM64_PGTABLE_LEVELS > 2
+static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss;
+#endif
+#if CONFIG_ARM64_PGTABLE_LEVELS > 3
+static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss;
+#endif
+
+static inline pud_t * fixmap_pud(unsigned long addr)
+{
+       pgd_t *pgd = pgd_offset_k(addr);
+
+       BUG_ON(pgd_none(*pgd) || pgd_bad(*pgd));
+
+       return pud_offset(pgd, addr);
+}
+
+static inline pmd_t * fixmap_pmd(unsigned long addr)
+{
+       pud_t *pud = fixmap_pud(addr);
+
+       BUG_ON(pud_none(*pud) || pud_bad(*pud));
+
+       return pmd_offset(pud, addr);
+}
+
+static inline pte_t * fixmap_pte(unsigned long addr)
+{
+       pmd_t *pmd = fixmap_pmd(addr);
+
+       BUG_ON(pmd_none(*pmd) || pmd_bad(*pmd));
+
+       return pte_offset_kernel(pmd, addr);
+}
+
+void __init early_fixmap_init(void)
+{
+       pgd_t *pgd;
+       pud_t *pud;
+       pmd_t *pmd;
+       unsigned long addr = FIXADDR_START;
+
+       pgd = pgd_offset_k(addr);
+       pgd_populate(&init_mm, pgd, bm_pud);
+       pud = pud_offset(pgd, addr);
+       pud_populate(&init_mm, pud, bm_pmd);
+       pmd = pmd_offset(pud, addr);
+       pmd_populate_kernel(&init_mm, pmd, bm_pte);
+
+       /*
+        * The boot-ioremap range spans multiple pmds, for which
+        * we are not preparted:
+        */
+       BUILD_BUG_ON((__fix_to_virt(FIX_BTMAP_BEGIN) >> PMD_SHIFT)
+                    != (__fix_to_virt(FIX_BTMAP_END) >> PMD_SHIFT));
+
+       if ((pmd != fixmap_pmd(fix_to_virt(FIX_BTMAP_BEGIN)))
+            || pmd != fixmap_pmd(fix_to_virt(FIX_BTMAP_END))) {
+               WARN_ON(1);
+               pr_warn("pmd %p != %p, %p\n",
+                       pmd, fixmap_pmd(fix_to_virt(FIX_BTMAP_BEGIN)),
+                       fixmap_pmd(fix_to_virt(FIX_BTMAP_END)));
+               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);
+       }
+}
+
+void __set_fixmap(enum fixed_addresses idx,
+                              phys_addr_t phys, pgprot_t flags)
+{
+       unsigned long addr = __fix_to_virt(idx);
+       pte_t *pte;
+
+       if (idx >= __end_of_fixed_addresses) {
+               BUG();
+               return;
+       }
+
+       pte = fixmap_pte(addr);
+
+       if (pgprot_val(flags)) {
+               set_pte(pte, pfn_pte(phys >> PAGE_SHIFT, flags));
+       } else {
+               pte_clear(&init_mm, addr, pte);
+               flush_tlb_kernel_range(addr, addr+PAGE_SIZE);
+       }
+}