Merge branch 'x86-debug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[GitHub/moto-9609/android_kernel_motorola_exynos9610.git] / arch / parisc / include / asm / pgalloc.h
CommitLineData
1da177e4
LT
1#ifndef _ASM_PGALLOC_H
2#define _ASM_PGALLOC_H
3
4#include <linux/gfp.h>
5#include <linux/mm.h>
6#include <linux/threads.h>
7#include <asm/processor.h>
8#include <asm/fixmap.h>
9
10#include <asm/cache.h>
11
12/* Allocate the top level pgd (page directory)
13 *
14 * Here (for 64 bit kernels) we implement a Hybrid L2/L3 scheme: we
15 * allocate the first pmd adjacent to the pgd. This means that we can
16 * subtract a constant offset to get to it. The pmd and pgd sizes are
513e7ecd 17 * arranged so that a single pmd covers 4GB (giving a full 64-bit
1da177e4
LT
18 * process access to 8TB) so our lookups are effectively L2 for the
19 * first 4GB of the kernel (i.e. for all ILP32 processes and all the
20 * kernel for machines with under 4GB of memory) */
21static inline pgd_t *pgd_alloc(struct mm_struct *mm)
22{
23 pgd_t *pgd = (pgd_t *)__get_free_pages(GFP_KERNEL,
24 PGD_ALLOC_ORDER);
25 pgd_t *actual_pgd = pgd;
26
27 if (likely(pgd != NULL)) {
28 memset(pgd, 0, PAGE_SIZE<<PGD_ALLOC_ORDER);
c19edb69 29#if CONFIG_PGTABLE_LEVELS == 3
1da177e4
LT
30 actual_pgd += PTRS_PER_PGD;
31 /* Populate first pmd with allocated memory. We mark it
32 * with PxD_FLAG_ATTACHED as a signal to the system that this
33 * pmd entry may not be cleared. */
34 __pgd_val_set(*actual_pgd, (PxD_FLAG_PRESENT |
35 PxD_FLAG_VALID |
36 PxD_FLAG_ATTACHED)
37 + (__u32)(__pa((unsigned long)pgd) >> PxD_VALUE_SHIFT));
2b3f3445 38 /* The first pmd entry also is marked with PxD_FLAG_ATTACHED as
1da177e4
LT
39 * a signal that this pmd may not be freed */
40 __pgd_val_set(*pgd, PxD_FLAG_ATTACHED);
41#endif
42 }
43 return actual_pgd;
44}
45
5e541973 46static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
1da177e4 47{
c19edb69 48#if CONFIG_PGTABLE_LEVELS == 3
1da177e4
LT
49 pgd -= PTRS_PER_PGD;
50#endif
51 free_pages((unsigned long)pgd, PGD_ALLOC_ORDER);
52}
53
f24ffde4 54#if CONFIG_PGTABLE_LEVELS == 3
1da177e4
LT
55
56/* Three Level Page Table Support for pmd's */
57
58static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
59{
60 __pgd_val_set(*pgd, (PxD_FLAG_PRESENT | PxD_FLAG_VALID) +
61 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
62}
63
64static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
65{
aade311a 66 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL, PMD_ORDER);
1da177e4
LT
67 if (pmd)
68 memset(pmd, 0, PAGE_SIZE<<PMD_ORDER);
69 return pmd;
70}
71
5e541973 72static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
1da177e4 73{
4c4ac9a4 74 if (pmd_flag(*pmd) & PxD_FLAG_ATTACHED) {
0e0da48d
MP
75 /*
76 * This is the permanent pmd attached to the pgd;
77 * cannot free it.
78 * Increment the counter to compensate for the decrement
79 * done by generic mm code.
80 */
81 mm_inc_nr_pmds(mm);
1da177e4 82 return;
4c4ac9a4 83 }
1da177e4
LT
84 free_pages((unsigned long)pmd, PMD_ORDER);
85}
86
87#else
88
89/* Two Level Page Table Support for pmd's */
90
91/*
92 * allocating and freeing a pmd is trivial: the 1-entry pmd is
93 * inside the pgd, so has no extra memory associated with it.
94 */
95
96#define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5e541973 97#define pmd_free(mm, x) do { } while (0)
1da177e4
LT
98#define pgd_populate(mm, pmd, pte) BUG()
99
100#endif
101
102static inline void
103pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
104{
c19edb69 105#if CONFIG_PGTABLE_LEVELS == 3
1da177e4
LT
106 /* preserve the gateway marker if this is the beginning of
107 * the permanent pmd */
108 if(pmd_flag(*pmd) & PxD_FLAG_ATTACHED)
109 __pmd_val_set(*pmd, (PxD_FLAG_PRESENT |
110 PxD_FLAG_VALID |
111 PxD_FLAG_ATTACHED)
112 + (__u32)(__pa((unsigned long)pte) >> PxD_VALUE_SHIFT));
113 else
114#endif
115 __pmd_val_set(*pmd, (PxD_FLAG_PRESENT | PxD_FLAG_VALID)
116 + (__u32)(__pa((unsigned long)pte) >> PxD_VALUE_SHIFT));
117}
118
119#define pmd_populate(mm, pmd, pte_page) \
120 pmd_populate_kernel(mm, pmd, page_address(pte_page))
2f569afd 121#define pmd_pgtable(pmd) pmd_page(pmd)
1da177e4 122
2f569afd 123static inline pgtable_t
1da177e4
LT
124pte_alloc_one(struct mm_struct *mm, unsigned long address)
125{
32d6bd90 126 struct page *page = alloc_page(GFP_KERNEL|__GFP_ZERO);
bc16640d
KS
127 if (!page)
128 return NULL;
129 if (!pgtable_page_ctor(page)) {
130 __free_page(page);
131 return NULL;
132 }
1da177e4
LT
133 return page;
134}
135
136static inline pte_t *
137pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
138{
32d6bd90 139 pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
1da177e4
LT
140 return pte;
141}
142
5e541973 143static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
1da177e4
LT
144{
145 free_page((unsigned long)pte);
146}
147
9aa150b8 148static inline void pte_free(struct mm_struct *mm, struct page *pte)
2f569afd
MS
149{
150 pgtable_page_dtor(pte);
9aa150b8 151 pte_free_kernel(mm, page_address(pte));
2f569afd 152}
1da177e4 153
1da177e4
LT
154#define check_pgt_cache() do { } while (0)
155
156#endif