Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / include / asm-s390 / 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 (hp@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/threads.h>
17 #include <linux/gfp.h>
18 #include <linux/mm.h>
19
20 #define arch_add_exec_range(mm, limit) do { ; } while (0)
21 #define arch_flush_exec_range(mm)      do { ; } while (0)
22 #define arch_remove_exec_range(mm, limit) do { ; } while (0)
23
24 #define check_pgt_cache()       do {} while (0)
25
26 extern void diag10(unsigned long addr);
27
28 /*
29  * Allocate and free page tables. The xxx_kernel() versions are
30  * used to allocate a kernel page table - this turns on ASN bits
31  * if any.
32  */
33
34 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
35 {
36         pgd_t *pgd;
37         int i;
38
39 #ifndef __s390x__
40         pgd = (pgd_t *) __get_free_pages(GFP_KERNEL,1);
41         if (pgd != NULL)
42                 for (i = 0; i < USER_PTRS_PER_PGD; i++)
43                         pmd_clear(pmd_offset(pgd + i, i*PGDIR_SIZE));
44 #else /* __s390x__ */
45         pgd = (pgd_t *) __get_free_pages(GFP_KERNEL,2);
46         if (pgd != NULL)
47                 for (i = 0; i < PTRS_PER_PGD; i++)
48                         pgd_clear(pgd + i);
49 #endif /* __s390x__ */
50         return pgd;
51 }
52
53 static inline void pgd_free(pgd_t *pgd)
54 {
55 #ifndef __s390x__
56         free_pages((unsigned long) pgd, 1);
57 #else /* __s390x__ */
58         free_pages((unsigned long) pgd, 2);
59 #endif /* __s390x__ */
60 }
61
62 #ifndef __s390x__
63 /*
64  * page middle directory allocation/free routines.
65  * We use pmd cache only on s390x, so these are dummy routines. This
66  * code never triggers because the pgd will always be present.
67  */
68 #define pmd_alloc_one(mm,address)       ({ BUG(); ((pmd_t *)2); })
69 #define pmd_free(x)                     do { } while (0)
70 #define __pmd_free_tlb(tlb,x)           do { } while (0)
71 #define pgd_populate(mm, pmd, pte)      BUG()
72 #else /* __s390x__ */
73 static inline pmd_t * pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
74 {
75         pmd_t *pmd;
76         int i;
77
78         pmd = (pmd_t *) __get_free_pages(GFP_KERNEL, 2);
79         if (pmd != NULL) {
80                 for (i=0; i < PTRS_PER_PMD; i++)
81                         pmd_clear(pmd+i);
82         }
83         return pmd;
84 }
85
86 static inline void pmd_free (pmd_t *pmd)
87 {
88         free_pages((unsigned long) pmd, 2);
89 }
90
91 #define __pmd_free_tlb(tlb,pmd)                 \
92         do {                                    \
93                 tlb_flush_mmu(tlb, 0, 0);       \
94                 pmd_free(pmd);                  \
95          } while (0)
96
97 static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
98 {
99         pgd_val(*pgd) = _PGD_ENTRY | __pa(pmd);
100 }
101
102 #endif /* __s390x__ */
103
104 static inline void 
105 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
106 {
107 #ifndef __s390x__
108         pmd_val(pmd[0]) = _PAGE_TABLE + __pa(pte);
109         pmd_val(pmd[1]) = _PAGE_TABLE + __pa(pte+256);
110         pmd_val(pmd[2]) = _PAGE_TABLE + __pa(pte+512);
111         pmd_val(pmd[3]) = _PAGE_TABLE + __pa(pte+768);
112 #else /* __s390x__ */
113         pmd_val(*pmd) = _PMD_ENTRY + __pa(pte);
114         pmd_val1(*pmd) = _PMD_ENTRY + __pa(pte+256);
115 #endif /* __s390x__ */
116 }
117
118 static inline void
119 pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *page)
120 {
121         pmd_populate_kernel(mm, pmd, (pte_t *)((page-mem_map) << PAGE_SHIFT));
122 }
123
124 /*
125  * page table entry allocation/free routines.
126  */
127 static inline pte_t *
128 pte_alloc_one_kernel(struct mm_struct *mm, unsigned long vmaddr)
129 {
130         pte_t *pte;
131         int i;
132
133         pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
134         if (pte != NULL) {
135                 for (i=0; i < PTRS_PER_PTE; i++) {
136                         pte_clear(mm, vmaddr, pte+i);
137                         vmaddr += PAGE_SIZE;
138                 }
139         }
140         return pte;
141 }
142
143 static inline struct page *
144 pte_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
145 {
146         pte_t *pte = pte_alloc_one_kernel(mm, vmaddr);
147         if (pte)
148                 return virt_to_page(pte);
149         return NULL;
150 }
151
152 static inline void pte_free_kernel(pte_t *pte)
153 {
154         free_page((unsigned long) pte);
155 }
156
157 static inline void pte_free(struct page *pte)
158 {
159         __free_page(pte);
160 }
161
162 #define __pte_free_tlb(tlb,pte) tlb_remove_page(tlb,pte)
163
164 #endif /* _S390_PGALLOC_H */