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