aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-x86_64/pgalloc.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-x86_64/pgalloc.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/asm-x86_64/pgalloc.h')
-rw-r--r--include/asm-x86_64/pgalloc.h105
1 files changed, 105 insertions, 0 deletions
diff --git a/include/asm-x86_64/pgalloc.h b/include/asm-x86_64/pgalloc.h
new file mode 100644
index 000000000000..deadd146978b
--- /dev/null
+++ b/include/asm-x86_64/pgalloc.h
@@ -0,0 +1,105 @@
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 pmd_populate_kernel(mm, pmd, pte) \
10 set_pmd(pmd, __pmd(_PAGE_TABLE | __pa(pte)))
11#define pud_populate(mm, pud, pmd) \
12 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)))
13#define pgd_populate(mm, pgd, pud) \
14 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)))
15
16static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte)
17{
18 set_pmd(pmd, __pmd(_PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT)));
19}
20
21extern __inline__ pmd_t *get_pmd(void)
22{
23 return (pmd_t *)get_zeroed_page(GFP_KERNEL);
24}
25
26extern __inline__ void pmd_free(pmd_t *pmd)
27{
28 BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
29 free_page((unsigned long)pmd);
30}
31
32static inline pmd_t *pmd_alloc_one (struct mm_struct *mm, unsigned long addr)
33{
34 return (pmd_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
35}
36
37static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
38{
39 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
40}
41
42static inline void pud_free (pud_t *pud)
43{
44 BUG_ON((unsigned long)pud & (PAGE_SIZE-1));
45 free_page((unsigned long)pud);
46}
47
48static inline pgd_t *pgd_alloc(struct mm_struct *mm)
49{
50 unsigned boundary;
51 pgd_t *pgd = (pgd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
52 if (!pgd)
53 return NULL;
54 /*
55 * Copy kernel pointers in from init.
56 * Could keep a freelist or slab cache of those because the kernel
57 * part never changes.
58 */
59 boundary = pgd_index(__PAGE_OFFSET);
60 memset(pgd, 0, boundary * sizeof(pgd_t));
61 memcpy(pgd + boundary,
62 init_level4_pgt + boundary,
63 (PTRS_PER_PGD - boundary) * sizeof(pgd_t));
64 return pgd;
65}
66
67static inline void pgd_free(pgd_t *pgd)
68{
69 BUG_ON((unsigned long)pgd & (PAGE_SIZE-1));
70 free_page((unsigned long)pgd);
71}
72
73static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
74{
75 return (pte_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
76}
77
78static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
79{
80 void *p = (void *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
81 if (!p)
82 return NULL;
83 return virt_to_page(p);
84}
85
86/* Should really implement gc for free page table pages. This could be
87 done with a reference count in struct page. */
88
89extern __inline__ void pte_free_kernel(pte_t *pte)
90{
91 BUG_ON((unsigned long)pte & (PAGE_SIZE-1));
92 free_page((unsigned long)pte);
93}
94
95extern inline void pte_free(struct page *pte)
96{
97 __free_page(pte);
98}
99
100#define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
101
102#define __pmd_free_tlb(tlb,x) tlb_remove_page((tlb),virt_to_page(x))
103#define __pud_free_tlb(tlb,x) tlb_remove_page((tlb),virt_to_page(x))
104
105#endif /* _X86_64_PGALLOC_H */