diff options
author | Catalin Marinas <catalin.marinas@arm.com> | 2011-11-22 12:30:29 -0500 |
---|---|---|
committer | Catalin Marinas <catalin.marinas@arm.com> | 2011-12-08 05:30:39 -0500 |
commit | da02877987e6e173ebba137d4e1e155e1f1151cd (patch) | |
tree | 8035bb1fb7def068ed2fd13d5d11ec5857c7d338 /arch/arm/include | |
parent | dcfdae04bd92e8a2ea155db0e21e3bddc09e0a89 (diff) |
ARM: LPAE: Page table maintenance for the 3-level format
This patch modifies the pgd/pmd/pte manipulation functions to support
the 3-level page table format. Since there is no need for an 'ext'
argument to cpu_set_pte_ext(), this patch conditionally defines a
different prototype for this function when CONFIG_ARM_LPAE.
The patch also introduces the L_PGD_SWAPPER flag to mark pgd entries
pointing to pmd tables pre-allocated in the swapper_pg_dir and avoid
trying to free them at run-time. This flag is 0 with the classic page
table format.
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Diffstat (limited to 'arch/arm/include')
-rw-r--r-- | arch/arm/include/asm/pgalloc.h | 24 | ||||
-rw-r--r-- | arch/arm/include/asm/pgtable-3level.h | 53 | ||||
-rw-r--r-- | arch/arm/include/asm/proc-fns.h | 21 |
3 files changed, 98 insertions, 0 deletions
diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h index 7418894a737f..943504f53f57 100644 --- a/arch/arm/include/asm/pgalloc.h +++ b/arch/arm/include/asm/pgalloc.h | |||
@@ -25,6 +25,26 @@ | |||
25 | #define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER)) | 25 | #define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER)) |
26 | #define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL)) | 26 | #define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL)) |
27 | 27 | ||
28 | #ifdef CONFIG_ARM_LPAE | ||
29 | |||
30 | static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr) | ||
31 | { | ||
32 | return (pmd_t *)get_zeroed_page(GFP_KERNEL | __GFP_REPEAT); | ||
33 | } | ||
34 | |||
35 | static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd) | ||
36 | { | ||
37 | BUG_ON((unsigned long)pmd & (PAGE_SIZE-1)); | ||
38 | free_page((unsigned long)pmd); | ||
39 | } | ||
40 | |||
41 | static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd) | ||
42 | { | ||
43 | set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE)); | ||
44 | } | ||
45 | |||
46 | #else /* !CONFIG_ARM_LPAE */ | ||
47 | |||
28 | /* | 48 | /* |
29 | * Since we have only two-level page tables, these are trivial | 49 | * Since we have only two-level page tables, these are trivial |
30 | */ | 50 | */ |
@@ -32,6 +52,8 @@ | |||
32 | #define pmd_free(mm, pmd) do { } while (0) | 52 | #define pmd_free(mm, pmd) do { } while (0) |
33 | #define pud_populate(mm,pmd,pte) BUG() | 53 | #define pud_populate(mm,pmd,pte) BUG() |
34 | 54 | ||
55 | #endif /* CONFIG_ARM_LPAE */ | ||
56 | |||
35 | extern pgd_t *pgd_alloc(struct mm_struct *mm); | 57 | extern pgd_t *pgd_alloc(struct mm_struct *mm); |
36 | extern void pgd_free(struct mm_struct *mm, pgd_t *pgd); | 58 | extern void pgd_free(struct mm_struct *mm, pgd_t *pgd); |
37 | 59 | ||
@@ -109,7 +131,9 @@ static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte, | |||
109 | { | 131 | { |
110 | pmdval_t pmdval = (pte + PTE_HWTABLE_OFF) | prot; | 132 | pmdval_t pmdval = (pte + PTE_HWTABLE_OFF) | prot; |
111 | pmdp[0] = __pmd(pmdval); | 133 | pmdp[0] = __pmd(pmdval); |
134 | #ifndef CONFIG_ARM_LPAE | ||
112 | pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t)); | 135 | pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t)); |
136 | #endif | ||
113 | flush_pmd_entry(pmdp); | 137 | flush_pmd_entry(pmdp); |
114 | } | 138 | } |
115 | 139 | ||
diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h index 79bf0acc40db..759af70f9a0a 100644 --- a/arch/arm/include/asm/pgtable-3level.h +++ b/arch/arm/include/asm/pgtable-3level.h | |||
@@ -99,4 +99,57 @@ | |||
99 | #define L_PTE_MT_DEV_CACHED (_AT(pteval_t, 3) << 2) /* normal inner write-back */ | 99 | #define L_PTE_MT_DEV_CACHED (_AT(pteval_t, 3) << 2) /* normal inner write-back */ |
100 | #define L_PTE_MT_MASK (_AT(pteval_t, 7) << 2) | 100 | #define L_PTE_MT_MASK (_AT(pteval_t, 7) << 2) |
101 | 101 | ||
102 | /* | ||
103 | * Software PGD flags. | ||
104 | */ | ||
105 | #define L_PGD_SWAPPER (_AT(pgdval_t, 1) << 55) /* swapper_pg_dir entry */ | ||
106 | |||
107 | #ifndef __ASSEMBLY__ | ||
108 | |||
109 | #define pud_none(pud) (!pud_val(pud)) | ||
110 | #define pud_bad(pud) (!(pud_val(pud) & 2)) | ||
111 | #define pud_present(pud) (pud_val(pud)) | ||
112 | |||
113 | #define pud_clear(pudp) \ | ||
114 | do { \ | ||
115 | *pudp = __pud(0); \ | ||
116 | clean_pmd_entry(pudp); \ | ||
117 | } while (0) | ||
118 | |||
119 | #define set_pud(pudp, pud) \ | ||
120 | do { \ | ||
121 | *pudp = pud; \ | ||
122 | flush_pmd_entry(pudp); \ | ||
123 | } while (0) | ||
124 | |||
125 | static inline pmd_t *pud_page_vaddr(pud_t pud) | ||
126 | { | ||
127 | return __va(pud_val(pud) & PHYS_MASK & (s32)PAGE_MASK); | ||
128 | } | ||
129 | |||
130 | /* Find an entry in the second-level page table.. */ | ||
131 | #define pmd_index(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1)) | ||
132 | static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr) | ||
133 | { | ||
134 | return (pmd_t *)pud_page_vaddr(*pud) + pmd_index(addr); | ||
135 | } | ||
136 | |||
137 | #define pmd_bad(pmd) (!(pmd_val(pmd) & 2)) | ||
138 | |||
139 | #define copy_pmd(pmdpd,pmdps) \ | ||
140 | do { \ | ||
141 | *pmdpd = *pmdps; \ | ||
142 | flush_pmd_entry(pmdpd); \ | ||
143 | } while (0) | ||
144 | |||
145 | #define pmd_clear(pmdp) \ | ||
146 | do { \ | ||
147 | *pmdp = __pmd(0); \ | ||
148 | clean_pmd_entry(pmdp); \ | ||
149 | } while (0) | ||
150 | |||
151 | #define set_pte_ext(ptep,pte,ext) cpu_set_pte_ext(ptep,__pte(pte_val(pte)|(ext))) | ||
152 | |||
153 | #endif /* __ASSEMBLY__ */ | ||
154 | |||
102 | #endif /* _ASM_PGTABLE_3LEVEL_H */ | 155 | #endif /* _ASM_PGTABLE_3LEVEL_H */ |
diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h index 9e92cb205e65..f3628fb3d2b3 100644 --- a/arch/arm/include/asm/proc-fns.h +++ b/arch/arm/include/asm/proc-fns.h | |||
@@ -65,7 +65,11 @@ extern struct processor { | |||
65 | * Set a possibly extended PTE. Non-extended PTEs should | 65 | * Set a possibly extended PTE. Non-extended PTEs should |
66 | * ignore 'ext'. | 66 | * ignore 'ext'. |
67 | */ | 67 | */ |
68 | #ifdef CONFIG_ARM_LPAE | ||
69 | void (*set_pte_ext)(pte_t *ptep, pte_t pte); | ||
70 | #else | ||
68 | void (*set_pte_ext)(pte_t *ptep, pte_t pte, unsigned int ext); | 71 | void (*set_pte_ext)(pte_t *ptep, pte_t pte, unsigned int ext); |
72 | #endif | ||
69 | 73 | ||
70 | /* Suspend/resume */ | 74 | /* Suspend/resume */ |
71 | unsigned int suspend_size; | 75 | unsigned int suspend_size; |
@@ -79,7 +83,11 @@ extern void cpu_proc_fin(void); | |||
79 | extern int cpu_do_idle(void); | 83 | extern int cpu_do_idle(void); |
80 | extern void cpu_dcache_clean_area(void *, int); | 84 | extern void cpu_dcache_clean_area(void *, int); |
81 | extern void cpu_do_switch_mm(unsigned long pgd_phys, struct mm_struct *mm); | 85 | extern void cpu_do_switch_mm(unsigned long pgd_phys, struct mm_struct *mm); |
86 | #ifdef CONFIG_ARM_LPAE | ||
87 | extern void cpu_set_pte_ext(pte_t *ptep, pte_t pte); | ||
88 | #else | ||
82 | extern void cpu_set_pte_ext(pte_t *ptep, pte_t pte, unsigned int ext); | 89 | extern void cpu_set_pte_ext(pte_t *ptep, pte_t pte, unsigned int ext); |
90 | #endif | ||
83 | extern void cpu_reset(unsigned long addr) __attribute__((noreturn)); | 91 | extern void cpu_reset(unsigned long addr) __attribute__((noreturn)); |
84 | 92 | ||
85 | /* These three are private to arch/arm/kernel/suspend.c */ | 93 | /* These three are private to arch/arm/kernel/suspend.c */ |
@@ -107,6 +115,18 @@ extern void cpu_resume(void); | |||
107 | 115 | ||
108 | #define cpu_switch_mm(pgd,mm) cpu_do_switch_mm(virt_to_phys(pgd),mm) | 116 | #define cpu_switch_mm(pgd,mm) cpu_do_switch_mm(virt_to_phys(pgd),mm) |
109 | 117 | ||
118 | #ifdef CONFIG_ARM_LPAE | ||
119 | #define cpu_get_pgd() \ | ||
120 | ({ \ | ||
121 | unsigned long pg, pg2; \ | ||
122 | __asm__("mrrc p15, 0, %0, %1, c2" \ | ||
123 | : "=r" (pg), "=r" (pg2) \ | ||
124 | : \ | ||
125 | : "cc"); \ | ||
126 | pg &= ~(PTRS_PER_PGD*sizeof(pgd_t)-1); \ | ||
127 | (pgd_t *)phys_to_virt(pg); \ | ||
128 | }) | ||
129 | #else | ||
110 | #define cpu_get_pgd() \ | 130 | #define cpu_get_pgd() \ |
111 | ({ \ | 131 | ({ \ |
112 | unsigned long pg; \ | 132 | unsigned long pg; \ |
@@ -115,6 +135,7 @@ extern void cpu_resume(void); | |||
115 | pg &= ~0x3fff; \ | 135 | pg &= ~0x3fff; \ |
116 | (pgd_t *)phys_to_virt(pg); \ | 136 | (pgd_t *)phys_to_virt(pg); \ |
117 | }) | 137 | }) |
138 | #endif | ||
118 | 139 | ||
119 | #endif | 140 | #endif |
120 | 141 | ||