1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#ifndef _ASM_PGALLOC_H
22#define _ASM_PGALLOC_H
23
24#include <asm/mem-layout.h>
25#include <asm/atomic.h>
26
27#define check_pgt_cache() do {} while (0)
28
29extern unsigned long long kmap_generation;
30
31
32
33
34static inline pgd_t *pgd_alloc(struct mm_struct *mm)
35{
36 pgd_t *pgd;
37
38 pgd = (pgd_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
39
40
41
42
43
44
45
46
47
48 memcpy(pgd, swapper_pg_dir, PTRS_PER_PGD*sizeof(pgd_t));
49 mm->context.generation = kmap_generation;
50
51
52 mm->context.ptbase = __pa(pgd);
53
54 return pgd;
55}
56
57static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
58{
59 free_page((unsigned long) pgd);
60}
61
62static inline struct page *pte_alloc_one(struct mm_struct *mm,
63 unsigned long address)
64{
65 struct page *pte;
66
67 pte = alloc_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
68 if (!pte)
69 return NULL;
70 if (!pgtable_page_ctor(pte)) {
71 __free_page(pte);
72 return NULL;
73 }
74 return pte;
75}
76
77
78static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
79 unsigned long address)
80{
81 gfp_t flags = GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO;
82 return (pte_t *) __get_free_page(flags);
83}
84
85static inline void pte_free(struct mm_struct *mm, struct page *pte)
86{
87 pgtable_page_dtor(pte);
88 __free_page(pte);
89}
90
91static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
92{
93 free_page((unsigned long)pte);
94}
95
96static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
97 pgtable_t pte)
98{
99
100
101
102
103 set_pmd(pmd, __pmd(((unsigned long)page_to_pfn(pte) << PAGE_SHIFT) |
104 HEXAGON_L1_PTE_SIZE));
105}
106
107
108
109
110
111
112
113
114
115
116static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
117 pte_t *pte)
118{
119 extern spinlock_t kmap_gen_lock;
120 pmd_t *ppmd;
121 int pmdindex;
122
123 spin_lock(&kmap_gen_lock);
124 kmap_generation++;
125 mm->context.generation = kmap_generation;
126 current->active_mm->context.generation = kmap_generation;
127 spin_unlock(&kmap_gen_lock);
128
129 set_pmd(pmd, __pmd(((unsigned long)__pa(pte)) | HEXAGON_L1_PTE_SIZE));
130
131
132
133
134
135 pmdindex = (pgd_t *)pmd - mm->pgd;
136 ppmd = (pmd_t *)current->active_mm->pgd + pmdindex;
137 set_pmd(ppmd, __pmd(((unsigned long)__pa(pte)) | HEXAGON_L1_PTE_SIZE));
138 if (pmdindex > max_kernel_seg)
139 max_kernel_seg = pmdindex;
140}
141
142#define __pte_free_tlb(tlb, pte, addr) \
143do { \
144 pgtable_page_dtor((pte)); \
145 tlb_remove_page((tlb), (pte)); \
146} while (0)
147
148#endif
149