This commit was manufactured by cvs2svn to create tag
[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 <asm/processor.h>
18 #include <linux/threads.h>
19 #include <linux/gfp.h>
20 #include <linux/mm.h>
21
22 #define arch_add_exec_range(mm, limit) do { ; } while (0)
23 #define arch_flush_exec_range(mm)      do { ; } while (0)
24 #define arch_remove_exec_range(mm, limit) do { ; } while (0)
25
26 #define check_pgt_cache()       do {} while (0)
27
28 extern void diag10(unsigned long addr);
29
30 /*
31  * Allocate and free page tables. The xxx_kernel() versions are
32  * used to allocate a kernel page table - this turns on ASN bits
33  * if any.
34  */
35
36 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
37 {
38         pgd_t *pgd;
39         int i;
40
41 #ifndef __s390x__
42         pgd = (pgd_t *) __get_free_pages(GFP_KERNEL,1);
43         if (pgd != NULL)
44                 for (i = 0; i < USER_PTRS_PER_PGD; i++)
45                         pmd_clear(pmd_offset(pgd + i, i*PGDIR_SIZE));
46 #else /* __s390x__ */
47         pgd = (pgd_t *) __get_free_pages(GFP_KERNEL,2);
48         if (pgd != NULL)
49                 for (i = 0; i < PTRS_PER_PGD; i++)
50                         pgd_clear(pgd + i);
51 #endif /* __s390x__ */
52         return pgd;
53 }
54
55 static inline void pgd_free(pgd_t *pgd)
56 {
57 #ifndef __s390x__
58         free_pages((unsigned long) pgd, 1);
59 #else /* __s390x__ */
60         free_pages((unsigned long) pgd, 2);
61 #endif /* __s390x__ */
62 }
63
64 #ifndef __s390x__
65 /*
66  * page middle directory allocation/free routines.
67  * We use pmd cache only on s390x, so these are dummy routines. This
68  * code never triggers because the pgd will always be present.
69  */
70 #define pmd_alloc_one(mm,address)       ({ BUG(); ((pmd_t *)2); })
71 #define pmd_free(x)                     do { } while (0)
72 #define __pmd_free_tlb(tlb,x)           do { } while (0)
73 #define pgd_populate(mm, pmd, pte)      BUG()
74 #else /* __s390x__ */
75 static inline pmd_t * pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
76 {
77         pmd_t *pmd;
78         int i;
79
80         pmd = (pmd_t *) __get_free_pages(GFP_KERNEL, 2);
81         if (pmd != NULL) {
82                 for (i=0; i < PTRS_PER_PMD; i++)
83                         pmd_clear(pmd+i);
84         }
85         return pmd;
86 }
87
88 static inline void pmd_free (pmd_t *pmd)
89 {
90         free_pages((unsigned long) pmd, 2);
91 }
92
93 #define __pmd_free_tlb(tlb,pmd)                 \
94         do {                                    \
95                 tlb_flush_mmu(tlb, 0, 0);       \
96                 pmd_free(pmd);                  \
97          } while (0)
98
99 static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
100 {
101         pgd_val(*pgd) = _PGD_ENTRY | __pa(pmd);
102 }
103
104 #endif /* __s390x__ */
105
106 static inline void 
107 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
108 {
109 #ifndef __s390x__
110         pmd_val(pmd[0]) = _PAGE_TABLE + __pa(pte);
111         pmd_val(pmd[1]) = _PAGE_TABLE + __pa(pte+256);
112         pmd_val(pmd[2]) = _PAGE_TABLE + __pa(pte+512);
113         pmd_val(pmd[3]) = _PAGE_TABLE + __pa(pte+768);
114 #else /* __s390x__ */
115         pmd_val(*pmd) = _PMD_ENTRY + __pa(pte);
116         pmd_val1(*pmd) = _PMD_ENTRY + __pa(pte+256);
117 #endif /* __s390x__ */
118 }
119
120 static inline void
121 pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *page)
122 {
123         pmd_populate_kernel(mm, pmd, (pte_t *)((page-mem_map) << PAGE_SHIFT));
124 }
125
126 /*
127  * page table entry allocation/free routines.
128  */
129 static inline pte_t *
130 pte_alloc_one_kernel(struct mm_struct *mm, unsigned long vmaddr)
131 {
132         pte_t *pte;
133         int i;
134
135         pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
136         if (pte != NULL) {
137                 for (i=0; i < PTRS_PER_PTE; i++)
138                         pte_clear(pte+i);
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 0;
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 /*
165  * This establishes kernel virtual mappings (e.g., as a result of a
166  * vmalloc call).  Since s390-esame uses a separate kernel page table,
167  * there is nothing to do here... :)
168  */
169 #define set_pgdir(addr,entry) do { } while(0)
170
171 #endif /* _S390_PGALLOC_H */