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 = pgd_quicklist;
45
46         if (likely(ret != NULL)) {
47                 pgd_quicklist = (unsigned long *)(*ret);
48                 ret[0] = 0;
49                 --pgtable_cache_size;
50         } else
51                 ret = NULL;
52         return (pgd_t *) ret;
53 }
54
55 static inline pgd_t*
56 pgd_alloc (struct mm_struct *mm)
57 {
58         /* the VM system never calls pgd_alloc_one_fast(), so we do it here. */
59         pgd_t *pgd = pgd_alloc_one_fast(mm);
60
61         if (unlikely(pgd == NULL)) {
62                 pgd = (pgd_t *)__get_free_page(GFP_KERNEL);
63                 if (likely(pgd != NULL))
64                         clear_page(pgd);
65         }
66         return pgd;
67 }
68
69 static inline void
70 pgd_free (pgd_t *pgd)
71 {
72         *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
73         pgd_quicklist = (unsigned long *) pgd;
74         ++pgtable_cache_size;
75 }
76
77 static inline void
78 pgd_populate (struct mm_struct *mm, pgd_t *pgd_entry, pmd_t *pmd)
79 {
80         pgd_val(*pgd_entry) = __pa(pmd);
81 }
82
83
84 static inline pmd_t*
85 pmd_alloc_one_fast (struct mm_struct *mm, unsigned long addr)
86 {
87         unsigned long *ret = (unsigned long *)pmd_quicklist;
88
89         if (likely(ret != NULL)) {
90                 pmd_quicklist = (unsigned long *)(*ret);
91                 ret[0] = 0;
92                 --pgtable_cache_size;
93         }
94         return (pmd_t *)ret;
95 }
96
97 static inline pmd_t*
98 pmd_alloc_one (struct mm_struct *mm, unsigned long addr)
99 {
100         pmd_t *pmd = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
101
102         if (likely(pmd != NULL))
103                 clear_page(pmd);
104         return pmd;
105 }
106
107 static inline void
108 pmd_free (pmd_t *pmd)
109 {
110         *(unsigned long *)pmd = (unsigned long) pmd_quicklist;
111         pmd_quicklist = (unsigned long *) pmd;
112         ++pgtable_cache_size;
113 }
114
115 #define __pmd_free_tlb(tlb, pmd)        pmd_free(pmd)
116
117 static inline void
118 pmd_populate (struct mm_struct *mm, pmd_t *pmd_entry, struct page *pte)
119 {
120         pmd_val(*pmd_entry) = page_to_phys(pte);
121 }
122
123 static inline void
124 pmd_populate_kernel (struct mm_struct *mm, pmd_t *pmd_entry, pte_t *pte)
125 {
126         pmd_val(*pmd_entry) = __pa(pte);
127 }
128
129 static inline struct page *
130 pte_alloc_one (struct mm_struct *mm, unsigned long addr)
131 {
132         struct page *pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0);
133
134         if (likely(pte != NULL))
135                 clear_page(page_address(pte));
136         return pte;
137 }
138
139 static inline pte_t *
140 pte_alloc_one_kernel (struct mm_struct *mm, unsigned long addr)
141 {
142         pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
143
144         if (likely(pte != NULL))
145                 clear_page(pte);
146         return pte;
147 }
148
149 static inline void
150 pte_free (struct page *pte)
151 {
152         __free_page(pte);
153 }
154
155 static inline void
156 pte_free_kernel (pte_t *pte)
157 {
158         free_page((unsigned long) pte);
159 }
160
161 #define __pte_free_tlb(tlb, pte)        tlb_remove_page((tlb), (pte))
162
163 extern void check_pgt_cache (void);
164
165 #endif /* _ASM_IA64_PGALLOC_H */