blob: 57299446f7871d8b77adacdc27f7644b5e4c2168 [file] [log] [blame]
Russell King614dd052010-11-21 11:41:57 +00001#include <linux/kernel.h>
2
3#include <asm/cputype.h>
4#include <asm/pgalloc.h>
5#include <asm/pgtable.h>
6
Russell Kingaf3813d2010-11-21 11:48:16 +00007static void idmap_add_pmd(pgd_t *pgd, unsigned long addr, unsigned long end,
8 unsigned long prot)
9{
10 pmd_t *pmd = pmd_offset(pgd, addr);
11
12 addr = (addr & PMD_MASK) | prot;
13 pmd[0] = __pmd(addr);
14 addr += SECTION_SIZE;
15 pmd[1] = __pmd(addr);
16 flush_pmd_entry(pmd);
17}
18
Russell King614dd052010-11-21 11:41:57 +000019void identity_mapping_add(pgd_t *pgd, unsigned long addr, unsigned long end)
20{
Russell Kingaf3813d2010-11-21 11:48:16 +000021 unsigned long prot, next;
Russell King614dd052010-11-21 11:41:57 +000022
23 prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE;
24 if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
25 prot |= PMD_BIT4;
26
Russell Kingaf3813d2010-11-21 11:48:16 +000027 pgd += pgd_index(addr);
28 do {
29 next = pgd_addr_end(addr, end);
30 idmap_add_pmd(pgd, addr, next, prot);
31 } while (pgd++, addr = next, addr != end);
Russell King614dd052010-11-21 11:41:57 +000032}
33
34#ifdef CONFIG_SMP
Russell Kingaf3813d2010-11-21 11:48:16 +000035static void idmap_del_pmd(pgd_t *pgd, unsigned long addr, unsigned long end)
36{
37 pmd_t *pmd = pmd_offset(pgd, addr);
38 pmd_clear(pmd);
39}
40
Russell King614dd052010-11-21 11:41:57 +000041void identity_mapping_del(pgd_t *pgd, unsigned long addr, unsigned long end)
42{
Russell Kingaf3813d2010-11-21 11:48:16 +000043 unsigned long next;
44
45 pgd += pgd_index(addr);
46 do {
47 next = pgd_addr_end(addr, end);
48 idmap_del_pmd(pgd, addr, next);
49 } while (pgd++, addr = next, addr != end);
Russell King614dd052010-11-21 11:41:57 +000050}
51#endif
52
53/*
54 * In order to soft-boot, we need to insert a 1:1 mapping in place of
55 * the user-mode pages. This will then ensure that we have predictable
56 * results when turning the mmu off
57 */
58void setup_mm_for_reboot(char mode)
59{
60 /*
61 * We need to access to user-mode page tables here. For kernel threads
62 * we don't have any user-mode mappings so we use the context that we
63 * "borrowed".
64 */
65 identity_mapping_add(current->active_mm->pgd, 0, TASK_SIZE);
66 local_flush_tlb_all();
67}