vserver 1.9.5.x5
[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 /*
27  * Very stupidly, we used to get new pgd's and pmd's, init their contents
28  * to point to the NULL versions of the next level page table, later on
29  * completely re-init them the same way, then free them up.  This wasted
30  * a lot of work and caused unnecessary memory traffic.  How broken...
31  * We fix this by caching them.
32  */
33 #define pgd_quicklist           (local_cpu_data->pgd_quick)
34 #define pmd_quicklist           (local_cpu_data->pmd_quick)
35 #define pgtable_cache_size      (local_cpu_data->pgtable_cache_sz)
36
37 static inline pgd_t*
38 pgd_alloc_one_fast (struct mm_struct *mm)
39 {
40         unsigned long *ret = NULL;
41
42         preempt_disable();
43
44         ret = pgd_quicklist;
45         if (likely(ret != NULL)) {
46                 pgd_quicklist = (unsigned long *)(*ret);
47                 ret[0] = 0;
48                 --pgtable_cache_size;
49         } else
50                 ret = NULL;
51
52         preempt_enable();
53
54         return (pgd_t *) ret;
55 }
56
57 static inline pgd_t*
58 pgd_alloc (struct mm_struct *mm)
59 {
60         /* the VM system never calls pgd_alloc_one_fast(), so we do it here. */
61         pgd_t *pgd = pgd_alloc_one_fast(mm);
62
63         if (unlikely(pgd == NULL)) {
64                 pgd = (pgd_t *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
65         }
66         return pgd;
67 }
68
69 static inline void
70 pgd_free (pgd_t *pgd)
71 {
72         preempt_disable();
73         *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
74         pgd_quicklist = (unsigned long *) pgd;
75         ++pgtable_cache_size;
76         preempt_enable();
77 }
78
79 static inline void
80 pud_populate (struct mm_struct *mm, pud_t *pud_entry, pmd_t *pmd)
81 {
82         pud_val(*pud_entry) = __pa(pmd);
83 }
84
85 static inline pmd_t*
86 pmd_alloc_one_fast (struct mm_struct *mm, unsigned long addr)
87 {
88         unsigned long *ret = NULL;
89
90         preempt_disable();
91
92         ret = (unsigned long *)pmd_quicklist;
93         if (likely(ret != NULL)) {
94                 pmd_quicklist = (unsigned long *)(*ret);
95                 ret[0] = 0;
96                 --pgtable_cache_size;
97         }
98
99         preempt_enable();
100
101         return (pmd_t *)ret;
102 }
103
104 static inline pmd_t*
105 pmd_alloc_one (struct mm_struct *mm, unsigned long addr)
106 {
107         pmd_t *pmd = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
108
109         return pmd;
110 }
111
112 static inline void
113 pmd_free (pmd_t *pmd)
114 {
115         preempt_disable();
116         *(unsigned long *)pmd = (unsigned long) pmd_quicklist;
117         pmd_quicklist = (unsigned long *) pmd;
118         ++pgtable_cache_size;
119         preempt_enable();
120 }
121
122 #define __pmd_free_tlb(tlb, pmd)        pmd_free(pmd)
123
124 static inline void
125 pmd_populate (struct mm_struct *mm, pmd_t *pmd_entry, struct page *pte)
126 {
127         pmd_val(*pmd_entry) = page_to_phys(pte);
128 }
129
130 static inline void
131 pmd_populate_kernel (struct mm_struct *mm, pmd_t *pmd_entry, pte_t *pte)
132 {
133         pmd_val(*pmd_entry) = __pa(pte);
134 }
135
136 static inline struct page *
137 pte_alloc_one (struct mm_struct *mm, unsigned long addr)
138 {
139         struct page *pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
140
141         return pte;
142 }
143
144 static inline pte_t *
145 pte_alloc_one_kernel (struct mm_struct *mm, unsigned long addr)
146 {
147         pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
148
149         return pte;
150 }
151
152 static inline void
153 pte_free (struct page *pte)
154 {
155         __free_page(pte);
156 }
157
158 static inline void
159 pte_free_kernel (pte_t *pte)
160 {
161         free_page((unsigned long) pte);
162 }
163
164 #define __pte_free_tlb(tlb, pte)        tlb_remove_page((tlb), (pte))
165
166 extern void check_pgt_cache (void);
167
168 #endif /* _ASM_IA64_PGALLOC_H */