1 #ifndef _X86_64_PGALLOC_H
2 #define _X86_64_PGALLOC_H
4 #include <asm/fixmap.h>
6 #include <linux/threads.h>
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)
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)))
23 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte)
25 set_pmd(pmd, __pmd(_PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT)));
28 static inline pmd_t *get_pmd(void)
30 return (pmd_t *)get_zeroed_page(GFP_KERNEL);
33 static inline void pmd_free(pmd_t *pmd)
35 BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
36 free_page((unsigned long)pmd);
39 static inline pmd_t *pmd_alloc_one (struct mm_struct *mm, unsigned long addr)
41 return (pmd_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
44 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
46 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
49 static inline void pud_free (pud_t *pud)
51 BUG_ON((unsigned long)pud & (PAGE_SIZE-1));
52 free_page((unsigned long)pud);
55 static inline void pgd_list_add(pgd_t *pgd)
57 struct page *page = virt_to_page(pgd);
60 page->index = (pgoff_t)pgd_list;
62 pgd_list->private = (unsigned long)&page->index;
64 page->private = (unsigned long)&pgd_list;
65 spin_unlock(&pgd_lock);
68 static inline void pgd_list_del(pgd_t *pgd)
70 struct page *next, **pprev, *page = virt_to_page(pgd);
73 next = (struct page *)page->index;
74 pprev = (struct page **)page->private;
77 next->private = (unsigned long)pprev;
78 spin_unlock(&pgd_lock);
81 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
84 pgd_t *pgd = (pgd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
89 * Copy kernel pointers in from init.
90 * Could keep a freelist or slab cache of those because the kernel
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));
101 static inline void pgd_free(pgd_t *pgd)
103 BUG_ON((unsigned long)pgd & (PAGE_SIZE-1));
105 free_page((unsigned long)pgd);
108 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
110 return (pte_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
113 static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
115 void *p = (void *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
118 return virt_to_page(p);
121 /* Should really implement gc for free page table pages. This could be
122 done with a reference count in struct page. */
124 static inline void pte_free_kernel(pte_t *pte)
126 BUG_ON((unsigned long)pte & (PAGE_SIZE-1));
127 free_page((unsigned long)pte);
130 static inline void pte_free(struct page *pte)
135 #define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
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))
140 #endif /* _X86_64_PGALLOC_H */