vserver 1.9.5.x5
[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/processor.h>
5 #include <asm/fixmap.h>
6 #include <asm/pda.h>
7 #include <linux/threads.h>
8 #include <linux/mm.h>
9
10 #define pmd_populate_kernel(mm, pmd, pte) \
11                 set_pmd(pmd, __pmd(_PAGE_TABLE | __pa(pte)))
12 #define pud_populate(mm, pud, pmd) \
13                 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)))
14 #define pgd_populate(mm, pgd, pud) \
15                 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)))
16
17 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte)
18 {
19         set_pmd(pmd, __pmd(_PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT)));
20 }
21
22 extern __inline__ pmd_t *get_pmd(void)
23 {
24         return (pmd_t *)get_zeroed_page(GFP_KERNEL);
25 }
26
27 extern __inline__ void pmd_free(pmd_t *pmd)
28 {
29         BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
30         free_page((unsigned long)pmd);
31 }
32
33 static inline pmd_t *pmd_alloc_one (struct mm_struct *mm, unsigned long addr)
34 {
35         return (pmd_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
36 }
37
38 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
39 {
40         return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
41 }
42
43 static inline void pud_free (pud_t *pud)
44 {
45         BUG_ON((unsigned long)pud & (PAGE_SIZE-1));
46         free_page((unsigned long)pud);
47 }
48
49 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
50 {
51         unsigned boundary;
52         pgd_t *pgd = (pgd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
53         if (!pgd)
54                 return NULL;
55         /*
56          * Copy kernel pointers in from init.
57          * Could keep a freelist or slab cache of those because the kernel
58          * part never changes.
59          */
60         boundary = pgd_index(__PAGE_OFFSET);
61         memset(pgd, 0, boundary * sizeof(pgd_t));
62         memcpy(pgd + boundary,
63                init_level4_pgt + boundary,
64                (PTRS_PER_PGD - boundary) * sizeof(pgd_t));
65         return pgd;
66 }
67
68 static inline void pgd_free(pgd_t *pgd)
69 {
70         BUG_ON((unsigned long)pgd & (PAGE_SIZE-1));
71         free_page((unsigned long)pgd);
72 }
73
74 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
75 {
76         return (pte_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
77 }
78
79 static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
80 {
81         void *p = (void *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
82         if (!p)
83                 return NULL;
84         return virt_to_page(p);
85 }
86
87 /* Should really implement gc for free page table pages. This could be
88    done with a reference count in struct page. */
89
90 extern __inline__ void pte_free_kernel(pte_t *pte)
91 {
92         BUG_ON((unsigned long)pte & (PAGE_SIZE-1));
93         free_page((unsigned long)pte); 
94 }
95
96 extern inline void pte_free(struct page *pte)
97 {
98         __free_page(pte);
99
100
101 #define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
102 #define __pmd_free_tlb(tlb,x)   pmd_free(x)
103 #define __pud_free_tlb(tlb,x)   pud_free(x)
104
105 #endif /* _X86_64_PGALLOC_H */