1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1994 - 2001 by Ralf Baechle at alii
7 * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
8 */
9 #ifndef _ASM_PGALLOC_H
10 #define _ASM_PGALLOC_H
11
12 #include <linux/config.h>
13
14 /* TLB flushing:
15 *
16 * - flush_tlb_all() flushes all processes TLB entries
17 * - flush_tlb_mm(mm) flushes the specified mm context TLB entries
18 * - flush_tlb_page(mm, vmaddr) flushes a single page
19 * - flush_tlb_range(mm, start, end) flushes a range of pages
20 * - flush_tlb_pgtables(mm, start, end) flushes a range of page tables
21 * - flush_tlb_one(page) flushes a single kernel page
22 */
23 extern void local_flush_tlb_all(void);
24 extern void local_flush_tlb_mm(struct mm_struct *mm);
25 extern void local_flush_tlb_range(struct mm_struct *mm, unsigned long start,
26 unsigned long end);
27 extern void local_flush_tlb_page(struct vm_area_struct *vma,
28 unsigned long page);
29 extern void local_flush_tlb_one(unsigned long page);
30
31 #ifdef CONFIG_SMP
32
33 extern void flush_tlb_all(void);
34 extern void flush_tlb_mm(struct mm_struct *);
35 extern void flush_tlb_range(struct mm_struct *, unsigned long, unsigned long);
36 extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
37
38 #else /* CONFIG_SMP */
39
40 #define flush_tlb_all() local_flush_tlb_all()
41 #define flush_tlb_mm(mm) local_flush_tlb_mm(mm)
42 #define flush_tlb_range(mm,vmaddr,end) local_flush_tlb_range(mm, vmaddr, end)
43 #define flush_tlb_page(vma,page) local_flush_tlb_page(vma, page)
44
45 #endif /* CONFIG_SMP */
46
flush_tlb_pgtables(struct mm_struct * mm,unsigned long start,unsigned long end)47 static inline void flush_tlb_pgtables(struct mm_struct *mm,
48 unsigned long start, unsigned long end)
49 {
50 /* Nothing to do on MIPS. */
51 }
52
53
54 /*
55 * Allocate and free page tables.
56 */
57
58 #define pgd_quicklist (current_cpu_data.pgd_quick)
59 #define pmd_quicklist (current_cpu_data.pmd_quick)
60 #define pte_quicklist (current_cpu_data.pte_quick)
61 #define pgtable_cache_size (current_cpu_data.pgtable_cache_sz)
62
63 #define pmd_populate(mm, pmd, pte) pmd_set(pmd, pte)
64 #define pgd_populate(mm, pgd, pmd) pgd_set(pgd, pmd)
65
66 extern pgd_t *get_pgd_slow(void);
67
get_pgd_fast(void)68 static inline pgd_t *get_pgd_fast(void)
69 {
70 unsigned long *ret;
71
72 if((ret = pgd_quicklist) != NULL) {
73 pgd_quicklist = (unsigned long *)(*ret);
74 ret[0] = ret[1];
75 pgtable_cache_size--;
76 return (pgd_t *)ret;
77 }
78
79 ret = (unsigned long *) get_pgd_slow();
80 return (pgd_t *)ret;
81 }
82
free_pgd_fast(pgd_t * pgd)83 static inline void free_pgd_fast(pgd_t *pgd)
84 {
85 *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
86 pgd_quicklist = (unsigned long *) pgd;
87 pgtable_cache_size++;
88 }
89
free_pgd_slow(pgd_t * pgd)90 static inline void free_pgd_slow(pgd_t *pgd)
91 {
92 free_pages((unsigned long)pgd, PGD_ORDER);
93 }
94
pte_alloc_one(struct mm_struct * mm,unsigned long address)95 static inline pte_t *pte_alloc_one(struct mm_struct *mm, unsigned long address)
96 {
97 pte_t *pte;
98
99 pte = (pte_t *) __get_free_pages(GFP_KERNEL, PTE_ORDER);
100 if (pte)
101 clear_page(pte);
102 return pte;
103 }
104
pte_alloc_one_fast(struct mm_struct * mm,unsigned long address)105 static inline pte_t *pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
106 {
107 unsigned long *ret;
108
109 if ((ret = (unsigned long *)pte_quicklist) != NULL) {
110 pte_quicklist = (unsigned long *)(*ret);
111 ret[0] = ret[1];
112 pgtable_cache_size--;
113 }
114 return (pte_t *)ret;
115 }
116
117 extern pte_t *get_pte_slow(pmd_t *pmd, unsigned long address_preadjusted);
118
get_pte_fast(void)119 static inline pte_t *get_pte_fast(void)
120 {
121 unsigned long *ret;
122
123 if((ret = (unsigned long *)pte_quicklist) != NULL) {
124 pte_quicklist = (unsigned long *)(*ret);
125 ret[0] = ret[1];
126 pgtable_cache_size--;
127 }
128 return (pte_t *)ret;
129 }
130
free_pte_fast(pte_t * pte)131 static inline void free_pte_fast(pte_t *pte)
132 {
133 *(unsigned long *)pte = (unsigned long) pte_quicklist;
134 pte_quicklist = (unsigned long *) pte;
135 pgtable_cache_size++;
136 }
137
free_pte_slow(pte_t * pte)138 static inline void free_pte_slow(pte_t *pte)
139 {
140 free_pages((unsigned long)pte, PTE_ORDER);
141 }
142
pmd_alloc_one(struct mm_struct * mm,unsigned long address)143 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
144 {
145 pmd_t *pmd;
146
147 pmd = (pmd_t *) __get_free_pages(GFP_KERNEL, PMD_ORDER);
148 if (pmd)
149 pmd_init((unsigned long)pmd, (unsigned long)invalid_pte_table);
150 return pmd;
151 }
152
pmd_alloc_one_fast(struct mm_struct * mm,unsigned long address)153 static inline pmd_t *pmd_alloc_one_fast(struct mm_struct *mm, unsigned long address)
154 {
155 unsigned long *ret;
156
157 if ((ret = (unsigned long *)pmd_quicklist) != NULL) {
158 pmd_quicklist = (unsigned long *)(*ret);
159 ret[0] = ret[1];
160 pgtable_cache_size--;
161 }
162 return (pmd_t *)ret;
163 }
164
165 extern pmd_t *get_pmd_slow(pgd_t *pgd, unsigned long address_preadjusted);
166
get_pmd_fast(void)167 static inline pmd_t *get_pmd_fast(void)
168 {
169 unsigned long *ret;
170
171 if ((ret = (unsigned long *)pmd_quicklist) != NULL) {
172 pmd_quicklist = (unsigned long *)(*ret);
173 ret[0] = ret[1];
174 pgtable_cache_size--;
175 return (pmd_t *)ret;
176 }
177
178 return (pmd_t *)ret;
179 }
180
free_pmd_fast(pmd_t * pmd)181 static inline void free_pmd_fast(pmd_t *pmd)
182 {
183 *(unsigned long *)pmd = (unsigned long) pmd_quicklist;
184 pmd_quicklist = (unsigned long *) pmd;
185 pgtable_cache_size++;
186 }
187
free_pmd_slow(pmd_t * pmd)188 static inline void free_pmd_slow(pmd_t *pmd)
189 {
190 free_pages((unsigned long)pmd, PMD_ORDER);
191 }
192
193 #define pte_free(pte) free_pte_fast(pte)
194 #define pmd_free(pte) free_pmd_fast(pte)
195 #define pgd_free(pgd) free_pgd_fast(pgd)
196 #define pgd_alloc(mm) get_pgd_fast()
197
198 extern pte_t kptbl[(PAGE_SIZE << PGD_ORDER)/sizeof(pte_t)];
199 extern pmd_t kpmdtbl[PTRS_PER_PMD];
200
201 extern int do_check_pgt_cache(int, int);
202
203 #endif /* _ASM_PGALLOC_H */
204