fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / include / asm-x86_64 / pgalloc.h
1 #ifndef _X86_64_PGALLOC_H
2 #define _X86_64_PGALLOC_H
3
4 #include <asm/fixmap.h>
5 #include <asm/pda.h>
6 #include <linux/threads.h>
7 #include <linux/mm.h>
8
9 #define arch_add_exec_range(mm, limit) \
10                 do { (void)(mm), (void)(limit); } while (0)
11 #define arch_flush_exec_range(mm) \
12                 do { (void)(mm); } while (0)
13 #define arch_remove_exec_range(mm, limit) \
14                 do { (void)(mm), (void)(limit); } while (0)
15
16 #define pmd_populate_kernel(mm, pmd, pte) \
17                 set_pmd(pmd, __pmd(_PAGE_TABLE | __pa(pte)))
18 #define pud_populate(mm, pud, pmd) \
19                 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)))
20 #define pgd_populate(mm, pgd, pud) \
21                 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)))
22
23 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte)
24 {
25         set_pmd(pmd, __pmd(_PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT)));
26 }
27
28 static inline pmd_t *get_pmd(void)
29 {
30         return (pmd_t *)get_zeroed_page(GFP_KERNEL);
31 }
32
33 static inline void pmd_free(pmd_t *pmd)
34 {
35         BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
36         free_page((unsigned long)pmd);
37 }
38
39 static inline pmd_t *pmd_alloc_one (struct mm_struct *mm, unsigned long addr)
40 {
41         return (pmd_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
42 }
43
44 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
45 {
46         return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
47 }
48
49 static inline void pud_free (pud_t *pud)
50 {
51         BUG_ON((unsigned long)pud & (PAGE_SIZE-1));
52         free_page((unsigned long)pud);
53 }
54
55 static inline void pgd_list_add(pgd_t *pgd)
56 {
57         struct page *page = virt_to_page(pgd);
58
59         spin_lock(&pgd_lock);
60         page->index = (pgoff_t)pgd_list;
61         if (pgd_list)
62                 pgd_list->private = (unsigned long)&page->index;
63         pgd_list = page;
64         page->private = (unsigned long)&pgd_list;
65         spin_unlock(&pgd_lock);
66 }
67
68 static inline void pgd_list_del(pgd_t *pgd)
69 {
70         struct page *next, **pprev, *page = virt_to_page(pgd);
71
72         spin_lock(&pgd_lock);
73         next = (struct page *)page->index;
74         pprev = (struct page **)page->private;
75         *pprev = next;
76         if (next)
77                 next->private = (unsigned long)pprev;
78         spin_unlock(&pgd_lock);
79 }
80
81 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
82 {
83         unsigned boundary;
84         pgd_t *pgd = (pgd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
85         if (!pgd)
86                 return NULL;
87         pgd_list_add(pgd);
88         /*
89          * Copy kernel pointers in from init.
90          * Could keep a freelist or slab cache of those because the kernel
91          * part never changes.
92          */
93         boundary = pgd_index(__PAGE_OFFSET);
94         memset(pgd, 0, boundary * sizeof(pgd_t));
95         memcpy(pgd + boundary,
96                init_level4_pgt + boundary,
97                (PTRS_PER_PGD - boundary) * sizeof(pgd_t));
98         return pgd;
99 }
100
101 static inline void pgd_free(pgd_t *pgd)
102 {
103         BUG_ON((unsigned long)pgd & (PAGE_SIZE-1));
104         pgd_list_del(pgd);
105         free_page((unsigned long)pgd);
106 }
107
108 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
109 {
110         return (pte_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
111 }
112
113 static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
114 {
115         void *p = (void *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
116         if (!p)
117                 return NULL;
118         return virt_to_page(p);
119 }
120
121 /* Should really implement gc for free page table pages. This could be
122    done with a reference count in struct page. */
123
124 static inline void pte_free_kernel(pte_t *pte)
125 {
126         BUG_ON((unsigned long)pte & (PAGE_SIZE-1));
127         free_page((unsigned long)pte); 
128 }
129
130 static inline void pte_free(struct page *pte)
131 {
132         __free_page(pte);
133
134
135 #define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
136
137 #define __pmd_free_tlb(tlb,x)   tlb_remove_page((tlb),virt_to_page(x))
138 #define __pud_free_tlb(tlb,x)   tlb_remove_page((tlb),virt_to_page(x))
139
140 #endif /* _X86_64_PGALLOC_H */