make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / include / asm-s390x / pgalloc.h
1 /*
2  *  include/asm-s390/pgalloc.h
3  *
4  *  S390 version
5  *    Copyright (C) 1999, 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6  *    Author(s): Hartmut Penner (hpenner@de.ibm.com)
7  *               Martin Schwidefsky (schwidefsky@de.ibm.com)
8  *
9  *  Derived from "include/asm-i386/pgalloc.h"
10  *    Copyright (C) 1994  Linus Torvalds
11  */
12
13 #ifndef _S390_PGALLOC_H
14 #define _S390_PGALLOC_H
15
16 #include <linux/config.h>
17 #include <asm/processor.h>
18 #include <linux/threads.h>
19 #include <linux/slab.h>
20
21 #define pgd_quicklist (S390_lowcore.cpu_data.pgd_quick)
22 #define pmd_quicklist (S390_lowcore.cpu_data.pmd_quick)
23 #define pte_quicklist (S390_lowcore.cpu_data.pte_quick)
24 #define pgtable_cache_size (S390_lowcore.cpu_data.pgtable_cache_sz)
25
26 /*
27  * Allocate and free page tables. The xxx_kernel() versions are
28  * used to allocate a kernel page table - this turns on ASN bits
29  * if any.
30  */
31
32 /*
33  * page directory allocation/free routines.
34  */
35 extern __inline__ pgd_t *get_pgd_slow (void)
36 {
37         pgd_t *ret;
38         int i;
39
40         ret = (pgd_t *) __get_free_pages(GFP_KERNEL, 1);
41         if (ret != NULL)
42                 for (i = 0; i < PTRS_PER_PGD; i++) 
43                         pgd_clear(ret + i);
44         return ret;
45 }
46
47 extern __inline__ pgd_t *get_pgd_fast (void)
48 {
49         unsigned long *ret = pgd_quicklist;
50
51         if (ret != NULL) {
52                 pgd_quicklist = (unsigned long *)(*ret);
53                 ret[0] = ret[1];
54                 pgtable_cache_size -= 2;
55         }
56         return (pgd_t *) ret;
57 }
58
59 extern __inline__ pgd_t *pgd_alloc (struct mm_struct *mm)
60 {
61         pgd_t *pgd;
62
63         pgd = get_pgd_fast();
64         if (!pgd)
65                 pgd = get_pgd_slow();
66         return pgd;
67 }
68
69 extern __inline__ void free_pgd_fast (pgd_t *pgd)
70 {
71         *(unsigned long *) pgd = (unsigned long) pgd_quicklist;
72         pgd_quicklist = (unsigned long *) pgd;
73         pgtable_cache_size += 2;
74 }
75
76 extern __inline__ void free_pgd_slow (pgd_t *pgd)
77 {
78         free_pages((unsigned long) pgd, 1);
79 }
80
81 #define pgd_free(pgd)           free_pgd_fast(pgd)
82
83 extern pmd_t *pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd);
84
85 /*
86  * page middle directory allocation/free routines.
87  */
88 extern inline pmd_t * pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
89 {
90         pmd_t *pmd;
91         int i;
92
93         pmd = (pmd_t *) __get_free_pages(GFP_KERNEL, 1);
94         if (pmd != NULL) {
95                 for (i=0; i < PTRS_PER_PMD; i++)
96                         pmd_clear(pmd+i);
97         }
98         return pmd;
99 }
100
101 extern __inline__ pmd_t *
102 pmd_alloc_one_fast(struct mm_struct *mm, unsigned long address)
103 {
104         unsigned long *ret = (unsigned long *) pmd_quicklist;
105
106         if (ret != NULL) {
107                 pmd_quicklist = (unsigned long *)(*ret);
108                 ret[0] = ret[1];
109                 pgtable_cache_size -= 2;
110         }
111         return (pmd_t *) ret;
112 }
113
114 extern void pmd_free_order2(pmd_t *);
115 extern __inline__ void pmd_free_fast (pmd_t *pmd)
116 {
117         if (test_bit(PG_arch_1, &virt_to_page(pmd)->flags) == 0) {
118                 *(unsigned long *) pmd = (unsigned long) pmd_quicklist;
119                 pmd_quicklist = (unsigned long *) pmd;
120                 pgtable_cache_size += 2;
121         } else
122                 pmd_free_order2(pmd);
123 }
124
125 extern __inline__ void pmd_free_slow (pmd_t *pmd)
126 {
127         free_pages((unsigned long) pmd, 1);
128 }
129
130 #define pmd_free(pmd)           pmd_free_fast(pmd)
131
132 extern inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
133 {
134         pmd_val(*pmd) = _PMD_ENTRY | __pa(pte);
135         pmd_val1(*pmd) = _PMD_ENTRY | __pa(pte+256);
136 }
137
138 /*
139  * page table entry allocation/free routines.
140  */
141 extern inline pte_t * pte_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
142 {
143         pte_t *pte;
144         int i;
145
146         pte = (pte_t *) __get_free_page(GFP_KERNEL);
147         if (pte != NULL) {
148                 for (i=0; i < PTRS_PER_PTE; i++)
149                         pte_clear(pte+i);
150         }
151         return pte;
152 }
153
154 extern __inline__ pte_t* pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
155 {
156         unsigned long *ret = (unsigned long *) pte_quicklist;
157
158         if (ret != NULL) {
159                 pte_quicklist = (unsigned long *)(*ret);
160                 ret[0] = ret[1];
161                 pgtable_cache_size--;
162         }
163         return (pte_t *)ret;
164 }
165
166 extern __inline__ void pte_free_fast (pte_t *pte)
167 {
168         *(unsigned long *) pte = (unsigned long) pte_quicklist;
169         pte_quicklist = (unsigned long *) pte;
170         pgtable_cache_size++;
171 }
172
173 extern __inline__ void pte_free_slow (pte_t *pte)
174 {
175         free_page((unsigned long) pte);
176 }
177
178 #define pte_free(pte)           pte_free_fast(pte)
179
180 extern int do_check_pgt_cache (int, int);
181
182 /*
183  * This establishes kernel virtual mappings (e.g., as a result of a
184  * vmalloc call).  Since s390-esame uses a separate kernel page table,
185  * there is nothing to do here... :)
186  */
187 #define set_pgdir(vmaddr, entry)        do { } while(0)
188
189 /*
190  * TLB flushing:
191  *
192  *  - flush_tlb() flushes the current mm struct TLBs
193  *  - flush_tlb_all() flushes all processes TLBs 
194  *    called only from vmalloc/vfree
195  *  - flush_tlb_mm(mm) flushes the specified mm context TLB's
196  *  - flush_tlb_page(vma, vmaddr) flushes one page
197  *  - flush_tlb_range(mm, start, end) flushes a range of pages
198  *  - flush_tlb_pgtables(mm, start, end) flushes a range of page tables
199  */
200
201 /*
202  * S/390 has three ways of flushing TLBs
203  * 'ptlb' does a flush of the local processor
204  * 'csp' flushes the TLBs on all PUs of a SMP
205  * 'ipte' invalidates a pte in a page table and flushes that out of
206  * the TLBs of all PUs of a SMP
207  */
208
209 #define local_flush_tlb() \
210 do {  __asm__ __volatile__("ptlb": : :"memory"); } while (0)
211
212
213 #ifndef CONFIG_SMP
214
215 /*
216  * We always need to flush, since s390 does not flush tlb
217  * on each context switch
218  */
219
220 static inline void flush_tlb(void)
221 {
222         local_flush_tlb();
223 }
224 static inline void flush_tlb_all(void)
225 {
226         local_flush_tlb();
227 }
228 static inline void flush_tlb_mm(struct mm_struct *mm) 
229 {
230         local_flush_tlb();
231 }
232 static inline void flush_tlb_page(struct vm_area_struct *vma,
233                                   unsigned long addr)
234 {
235         local_flush_tlb();
236 }
237 static inline void flush_tlb_range(struct mm_struct *mm,
238                                    unsigned long start, unsigned long end)
239 {
240         local_flush_tlb();
241 }
242
243 #else
244
245 #include <asm/smp.h>
246
247 static inline void global_flush_tlb(void)
248 {
249         long dummy = 0;
250
251         __asm__ __volatile__ (
252                 "    la   4,3(%0)\n"
253                 "    nill 4,0xfffc\n"
254                 "    la   4,1(4)\n"
255                 "    slr  2,2\n"
256                 "    slr  3,3\n"
257                 "    csp  2,4"
258                 : : "a" (&dummy) : "cc", "2", "3", "4" );
259 }
260
261 /*
262  * We only have to do global flush of tlb if process run since last
263  * flush on any other pu than current. 
264  * If we have threads (mm->count > 1) we always do a global flush, 
265  * since the process runs on more than one processor at the same time.
266  */
267 static inline void __flush_tlb_mm(struct mm_struct * mm)
268 {
269         if ((smp_num_cpus > 1) &&
270             ((atomic_read(&mm->mm_count) != 1) ||
271              (mm->cpu_vm_mask != (1UL << smp_processor_id())))) {
272                 mm->cpu_vm_mask = (1UL << smp_processor_id());
273                 global_flush_tlb();
274         } else {                 
275                 local_flush_tlb();
276         }
277 }
278
279 static inline void flush_tlb(void)
280 {
281         __flush_tlb_mm(current->mm);
282 }
283 static inline void flush_tlb_all(void)
284 {
285         global_flush_tlb();
286 }
287 static inline void flush_tlb_mm(struct mm_struct *mm) 
288 {
289         __flush_tlb_mm(mm); 
290 }
291 static inline void flush_tlb_page(struct vm_area_struct *vma,
292                                   unsigned long addr)
293 {
294         __flush_tlb_mm(vma->vm_mm);
295 }
296 static inline void flush_tlb_range(struct mm_struct *mm,
297                                    unsigned long start, unsigned long end)
298 {
299         __flush_tlb_mm(mm); 
300 }
301
302 #endif
303
304 extern inline void flush_tlb_pgtables(struct mm_struct *mm,
305                                       unsigned long start, unsigned long end)
306 {
307         /* S/390 does not keep any page table caches in TLB */
308 }
309
310
311 static inline int ptep_test_and_clear_and_flush_young(struct vm_area_struct *vma, 
312                                                       unsigned long address, pte_t *ptep)
313 {
314         /* No need to flush TLB; bits are in storage key */
315         return ptep_test_and_clear_young(ptep);
316 }
317
318 static inline int ptep_test_and_clear_and_flush_dirty(struct vm_area_struct *vma, 
319                                                       unsigned long address, pte_t *ptep)
320 {
321         /* No need to flush TLB; bits are in storage key */
322         return ptep_test_and_clear_dirty(ptep);
323 }
324
325 static inline pte_t ptep_invalidate(struct vm_area_struct *vma, 
326                                     unsigned long address, pte_t *ptep)
327 {
328         pte_t pte = *ptep;
329         if (!(pte_val(pte) & _PAGE_INVALID)) 
330                 __asm__ __volatile__ ("ipte %0,%1" : : "a" (ptep), "a" (address));
331         pte_clear(ptep);
332         return pte;
333 }
334
335 static inline void ptep_establish(struct vm_area_struct *vma, 
336                                   unsigned long address, pte_t *ptep, pte_t entry)
337 {
338         ptep_invalidate(vma, address, ptep);
339         set_pte(ptep, entry);
340 }
341
342 #endif /* _S390_PGALLOC_H */