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