1 #include <linux/module.h>
2 #include <linux/kernel.h>
3 #include <linux/slab.h>
4 #include <linux/mm_types.h>
6 #include <asm/cputype.h>
8 #include <asm/pgalloc.h>
9 #include <asm/pgtable.h>
10 #include <asm/sections.h>
11 #include <asm/system_info.h>
14 * Note: accesses outside of the kernel image and the identity map area
15 * are not supported on any CPU using the idmap tables as its current
19 long long arch_phys_to_idmap_offset;
21 #ifdef CONFIG_ARM_LPAE
22 static void idmap_add_pmd(pud_t *pud, unsigned long addr, unsigned long end,
28 if (pud_none_or_clear_bad(pud) || (pud_val(*pud) & L_PGD_SWAPPER)) {
29 pmd = pmd_alloc_one(&init_mm, addr);
31 pr_warn("Failed to allocate identity pmd.\n");
35 * Copy the original PMD to ensure that the PMD entries for
36 * the kernel image are preserved.
39 memcpy(pmd, pmd_offset(pud, 0),
40 PTRS_PER_PMD * sizeof(pmd_t));
41 pud_populate(&init_mm, pud, pmd);
42 pmd += pmd_index(addr);
44 pmd = pmd_offset(pud, addr);
47 next = pmd_addr_end(addr, end);
48 *pmd = __pmd((addr & PMD_MASK) | prot);
50 } while (pmd++, addr = next, addr != end);
52 #else /* !CONFIG_ARM_LPAE */
53 static void idmap_add_pmd(pud_t *pud, unsigned long addr, unsigned long end,
56 pmd_t *pmd = pmd_offset(pud, addr);
58 addr = (addr & PMD_MASK) | prot;
64 #endif /* CONFIG_ARM_LPAE */
66 static void idmap_add_pud(pgd_t *pgd, unsigned long addr, unsigned long end,
69 pud_t *pud = pud_offset(pgd, addr);
73 next = pud_addr_end(addr, end);
74 idmap_add_pmd(pud, addr, next, prot);
75 } while (pud++, addr = next, addr != end);
78 static void identity_mapping_add(pgd_t *pgd, const char *text_start,
79 const char *text_end, unsigned long prot)
81 unsigned long addr, end;
84 addr = virt_to_idmap(text_start);
85 end = virt_to_idmap(text_end);
86 pr_info("Setting up static identity map for 0x%lx - 0x%lx\n", addr, end);
88 prot |= PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_AF;
90 if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale_family())
93 pgd += pgd_index(addr);
95 next = pgd_addr_end(addr, end);
96 idmap_add_pud(pgd, addr, next, prot);
97 } while (pgd++, addr = next, addr != end);
100 extern char __idmap_text_start[], __idmap_text_end[];
102 static int __init init_static_idmap(void)
104 idmap_pgd = pgd_alloc(&init_mm);
108 identity_mapping_add(idmap_pgd, __idmap_text_start,
109 __idmap_text_end, 0);
111 /* Flush L1 for the hardware to see this page table content */
116 early_initcall(init_static_idmap);
119 * In order to soft-boot, we need to switch to a 1:1 mapping for the
120 * cpu_reset functions. This will then ensure that we have predictable
121 * results when turning off the mmu.
123 void setup_mm_for_reboot(void)
125 /* Switch to the identity mapping. */
126 cpu_switch_mm(idmap_pgd, &init_mm);
127 local_flush_bp_all();
129 #ifdef CONFIG_CPU_HAS_ASID
131 * We don't have a clean ASID for the identity mapping, which
132 * may clash with virtual addresses of the previous page tables
133 * and therefore potentially in the TLB.
135 local_flush_tlb_all();