- Update Xen patches to 3.3-rc5 and c/s 1157.
[linux-flexiantxendom0-3.2.10.git] / arch / x86 / include / mach-xen / asm / pgalloc.h
1 #ifndef _ASM_X86_PGALLOC_H
2 #define _ASM_X86_PGALLOC_H
3
4 #include <linux/threads.h>
5 #include <linux/mm.h>           /* for struct page */
6 #include <linux/pagemap.h>
7
8 #include <asm/io.h>             /* for phys_to_virt and page_to_pseudophys */
9
10 static inline int paravirt_pgd_alloc(struct mm_struct *mm) { return 0; }
11 static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd) {}
12
13 static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned long pfn)  {}
14 static inline void paravirt_alloc_pmd(struct mm_struct *mm, unsigned long pfn)  {}
15 static inline void paravirt_alloc_pmd_clone(unsigned long pfn, unsigned long clonepfn,
16                                             unsigned long start, unsigned long count) {}
17 static inline void paravirt_alloc_pud(struct mm_struct *mm, unsigned long pfn)  {}
18 static inline void paravirt_release_pte(unsigned long pfn) {}
19 static inline void paravirt_release_pmd(unsigned long pfn) {}
20 static inline void paravirt_release_pud(unsigned long pfn) {}
21
22 #ifdef CONFIG_X86_64
23 void early_make_page_readonly(void *va, unsigned int feature);
24 pmd_t *early_get_pmd(unsigned long va);
25 #define make_lowmem_page_readonly make_page_readonly
26 #define make_lowmem_page_writable make_page_writable
27 #endif
28
29 /*
30  * Flags to use when allocating a user page table page.
31  */
32 extern gfp_t __userpte_alloc_gfp;
33
34 /*
35  * Allocate and free page tables.
36  */
37 extern pgd_t *pgd_alloc(struct mm_struct *);
38 extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
39
40 extern pte_t *pte_alloc_one_kernel(struct mm_struct *, unsigned long);
41 extern pgtable_t pte_alloc_one(struct mm_struct *, unsigned long);
42
43 /* Should really implement gc for free page table pages. This could be
44    done with a reference count in struct page. */
45
46 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
47 {
48         BUG_ON((unsigned long)pte & (PAGE_SIZE-1));
49         make_lowmem_page_writable(pte, XENFEAT_writable_page_tables);
50         free_page((unsigned long)pte);
51 }
52
53 extern void __pte_free(pgtable_t);
54 static inline void pte_free(struct mm_struct *mm, struct page *pte)
55 {
56         __pte_free(pte);
57 }
58
59 extern void ___pte_free_tlb(struct mmu_gather *tlb, struct page *pte);
60
61 static inline void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte,
62                                   unsigned long address)
63 {
64         ___pte_free_tlb(tlb, pte);
65 }
66
67 static inline void pmd_populate_kernel(struct mm_struct *mm,
68                                        pmd_t *pmd, pte_t *pte)
69 {
70         paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
71         set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
72 }
73
74 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
75                                 struct page *pte)
76 {
77         unsigned long pfn = page_to_pfn(pte);
78         pmd_t ent = __pmd(((pmdval_t)pfn << PAGE_SHIFT) | _PAGE_TABLE);
79
80         paravirt_alloc_pte(mm, pfn);
81         if (PagePinned(virt_to_page(pmd))) {
82 #ifndef CONFIG_HIGHPTE
83                 BUG_ON(PageHighMem(pte));
84 #endif
85                 set_pmd(pmd, ent);
86         } else
87                 *pmd = ent;
88 }
89
90 #define pmd_pgtable(pmd) pmd_page(pmd)
91
92 #if PAGETABLE_LEVELS > 2
93 extern pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr);
94 extern void __pmd_free(pgtable_t);
95
96 static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
97 {
98         BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
99         __pmd_free(virt_to_page(pmd));
100 }
101
102 extern void ___pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd);
103
104 static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
105                                   unsigned long address)
106 {
107         ___pmd_free_tlb(tlb, pmd);
108 }
109
110 #ifdef CONFIG_X86_PAE
111 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
112 #else   /* !CONFIG_X86_PAE */
113 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
114 {
115         pud_t ent = __pud(_PAGE_TABLE | __pa(pmd));
116
117         paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
118         if (PagePinned(virt_to_page(pud)))
119                 set_pud(pud, ent);
120         else
121                 *pud = ent;
122 }
123 #endif  /* CONFIG_X86_PAE */
124
125 #if PAGETABLE_LEVELS > 3
126 static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
127 {
128         pgd_t ent = __pgd(_PAGE_TABLE | __pa(pud));
129
130         paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
131         if (unlikely(PagePinned(virt_to_page(pgd))))
132                 xen_l4_entry_update(pgd, ent);
133         else
134                 *__user_pgd(pgd) = *pgd = ent;
135 }
136
137 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
138 {
139         return (pud_t *)pmd_alloc_one(mm, addr);
140 }
141
142 static inline void pud_free(struct mm_struct *mm, pud_t *pud)
143 {
144         BUG_ON((unsigned long)pud & (PAGE_SIZE-1));
145         __pmd_free(virt_to_page(pud));
146 }
147
148 extern void ___pud_free_tlb(struct mmu_gather *tlb, pud_t *pud);
149
150 static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
151                                   unsigned long address)
152 {
153         ___pud_free_tlb(tlb, pud);
154 }
155
156 #endif  /* PAGETABLE_LEVELS > 3 */
157 #endif  /* PAGETABLE_LEVELS > 2 */
158
159 #endif /* _ASM_X86_PGALLOC_H */