This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / include / asm-ia64 / pgalloc.h
1 #ifndef _ASM_IA64_PGALLOC_H
2 #define _ASM_IA64_PGALLOC_H
3
4 /*
5  * This file contains the functions and defines necessary to allocate
6  * page tables.
7  *
8  * This hopefully works with any (fixed) ia-64 page-size, as defined
9  * in <asm/page.h> (currently 8192).
10  *
11  * Copyright (C) 1998-2001 Hewlett-Packard Co
12  *      David Mosberger-Tang <davidm@hpl.hp.com>
13  * Copyright (C) 2000, Goutham Rao <goutham.rao@intel.com>
14  */
15
16 #include <linux/config.h>
17
18 #include <linux/compiler.h>
19 #include <linux/mm.h>
20 #include <linux/page-flags.h>
21 #include <linux/threads.h>
22
23 #include <asm/mmu_context.h>
24 #include <asm/processor.h>
25
26 #define arch_add_exec_range(mm, limit)          do { ; } while (0)
27 #define arch_flush_exec_range(mm)               do { ; } while (0)
28 #define arch_remove_exec_range(mm, limit)       do { ; } while (0)
29
30 /*
31  * Very stupidly, we used to get new pgd's and pmd's, init their contents
32  * to point to the NULL versions of the next level page table, later on
33  * completely re-init them the same way, then free them up.  This wasted
34  * a lot of work and caused unnecessary memory traffic.  How broken...
35  * We fix this by caching them.
36  */
37 #define pgd_quicklist           (local_cpu_data->pgd_quick)
38 #define pmd_quicklist           (local_cpu_data->pmd_quick)
39 #define pgtable_cache_size      (local_cpu_data->pgtable_cache_sz)
40
41 static inline pgd_t*
42 pgd_alloc_one_fast (struct mm_struct *mm)
43 {
44         unsigned long *ret = NULL;
45
46         preempt_disable();
47
48         ret = pgd_quicklist;
49         if (likely(ret != NULL)) {
50                 pgd_quicklist = (unsigned long *)(*ret);
51                 ret[0] = 0;
52                 --pgtable_cache_size;
53         } else
54                 ret = NULL;
55
56         preempt_enable();
57
58         return (pgd_t *) ret;
59 }
60
61 static inline pgd_t*
62 pgd_alloc (struct mm_struct *mm)
63 {
64         /* the VM system never calls pgd_alloc_one_fast(), so we do it here. */
65         pgd_t *pgd = pgd_alloc_one_fast(mm);
66
67         if (unlikely(pgd == NULL)) {
68                 pgd = (pgd_t *)__get_free_page(GFP_KERNEL);
69                 if (likely(pgd != NULL))
70                         clear_page(pgd);
71         }
72         return pgd;
73 }
74
75 static inline void
76 pgd_free (pgd_t *pgd)
77 {
78         preempt_disable();
79         *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
80         pgd_quicklist = (unsigned long *) pgd;
81         ++pgtable_cache_size;
82         preempt_enable();
83 }
84
85 static inline void
86 pgd_populate (struct mm_struct *mm, pgd_t *pgd_entry, pmd_t *pmd)
87 {
88         pgd_val(*pgd_entry) = __pa(pmd);
89 }
90
91
92 static inline pmd_t*
93 pmd_alloc_one_fast (struct mm_struct *mm, unsigned long addr)
94 {
95         unsigned long *ret = NULL;
96
97         preempt_disable();
98
99         ret = (unsigned long *)pmd_quicklist;
100         if (likely(ret != NULL)) {
101                 pmd_quicklist = (unsigned long *)(*ret);
102                 ret[0] = 0;
103                 --pgtable_cache_size;
104         }
105
106         preempt_enable();
107
108         return (pmd_t *)ret;
109 }
110
111 static inline pmd_t*
112 pmd_alloc_one (struct mm_struct *mm, unsigned long addr)
113 {
114         pmd_t *pmd = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
115
116         if (likely(pmd != NULL))
117                 clear_page(pmd);
118         return pmd;
119 }
120
121 static inline void
122 pmd_free (pmd_t *pmd)
123 {
124         preempt_disable();
125         *(unsigned long *)pmd = (unsigned long) pmd_quicklist;
126         pmd_quicklist = (unsigned long *) pmd;
127         ++pgtable_cache_size;
128         preempt_enable();
129 }
130
131 #define __pmd_free_tlb(tlb, pmd)        pmd_free(pmd)
132
133 static inline void
134 pmd_populate (struct mm_struct *mm, pmd_t *pmd_entry, struct page *pte)
135 {
136         pmd_val(*pmd_entry) = page_to_phys(pte);
137 }
138
139 static inline void
140 pmd_populate_kernel (struct mm_struct *mm, pmd_t *pmd_entry, pte_t *pte)
141 {
142         pmd_val(*pmd_entry) = __pa(pte);
143 }
144
145 static inline struct page *
146 pte_alloc_one (struct mm_struct *mm, unsigned long addr)
147 {
148         struct page *pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0);
149
150         if (likely(pte != NULL))
151                 clear_page(page_address(pte));
152         return pte;
153 }
154
155 static inline pte_t *
156 pte_alloc_one_kernel (struct mm_struct *mm, unsigned long addr)
157 {
158         pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
159
160         if (likely(pte != NULL))
161                 clear_page(pte);
162         return pte;
163 }
164
165 static inline void
166 pte_free (struct page *pte)
167 {
168         __free_page(pte);
169 }
170
171 static inline void
172 pte_free_kernel (pte_t *pte)
173 {
174         free_page((unsigned long) pte);
175 }
176
177 #define __pte_free_tlb(tlb, pte)        tlb_remove_page((tlb), (pte))
178
179 extern void check_pgt_cache (void);
180
181 #endif /* _ASM_IA64_PGALLOC_H */