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