This source file includes following definitions.
- pgd_alloc
- pgd_free
- pgd_populate
- pmd_alloc_one
- pmd_free
- pmd_populate_kernel
1
2 #ifndef _ASM_PGALLOC_H
3 #define _ASM_PGALLOC_H
4
5 #include <linux/gfp.h>
6 #include <linux/mm.h>
7 #include <linux/threads.h>
8 #include <asm/processor.h>
9 #include <asm/fixmap.h>
10
11 #include <asm/cache.h>
12
13 #include <asm-generic/pgalloc.h>
14
15
16
17
18
19
20
21
22
23
24 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
25 {
26 pgd_t *pgd = (pgd_t *)__get_free_pages(GFP_KERNEL,
27 PGD_ALLOC_ORDER);
28 pgd_t *actual_pgd = pgd;
29
30 if (likely(pgd != NULL)) {
31 memset(pgd, 0, PAGE_SIZE<<PGD_ALLOC_ORDER);
32 #if CONFIG_PGTABLE_LEVELS == 3
33 actual_pgd += PTRS_PER_PGD;
34
35
36
37 __pgd_val_set(*actual_pgd, (PxD_FLAG_PRESENT |
38 PxD_FLAG_VALID |
39 PxD_FLAG_ATTACHED)
40 + (__u32)(__pa((unsigned long)pgd) >> PxD_VALUE_SHIFT));
41
42
43 __pgd_val_set(*pgd, PxD_FLAG_ATTACHED);
44 #endif
45 }
46 spin_lock_init(pgd_spinlock(actual_pgd));
47 return actual_pgd;
48 }
49
50 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
51 {
52 #if CONFIG_PGTABLE_LEVELS == 3
53 pgd -= PTRS_PER_PGD;
54 #endif
55 free_pages((unsigned long)pgd, PGD_ALLOC_ORDER);
56 }
57
58 #if CONFIG_PGTABLE_LEVELS == 3
59
60
61
62 static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
63 {
64 __pgd_val_set(*pgd, (PxD_FLAG_PRESENT | PxD_FLAG_VALID) +
65 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
66 }
67
68 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
69 {
70 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL, PMD_ORDER);
71 if (pmd)
72 memset(pmd, 0, PAGE_SIZE<<PMD_ORDER);
73 return pmd;
74 }
75
76 static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
77 {
78 if (pmd_flag(*pmd) & PxD_FLAG_ATTACHED) {
79
80
81
82
83
84
85 mm_inc_nr_pmds(mm);
86 return;
87 }
88 free_pages((unsigned long)pmd, PMD_ORDER);
89 }
90
91 #else
92
93
94
95
96
97
98
99
100 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
101 #define pmd_free(mm, x) do { } while (0)
102 #define pgd_populate(mm, pmd, pte) BUG()
103
104 #endif
105
106 static inline void
107 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
108 {
109 #if CONFIG_PGTABLE_LEVELS == 3
110
111
112 if(pmd_flag(*pmd) & PxD_FLAG_ATTACHED)
113 __pmd_val_set(*pmd, (PxD_FLAG_PRESENT |
114 PxD_FLAG_VALID |
115 PxD_FLAG_ATTACHED)
116 + (__u32)(__pa((unsigned long)pte) >> PxD_VALUE_SHIFT));
117 else
118 #endif
119 __pmd_val_set(*pmd, (PxD_FLAG_PRESENT | PxD_FLAG_VALID)
120 + (__u32)(__pa((unsigned long)pte) >> PxD_VALUE_SHIFT));
121 }
122
123 #define pmd_populate(mm, pmd, pte_page) \
124 pmd_populate_kernel(mm, pmd, page_address(pte_page))
125 #define pmd_pgtable(pmd) pmd_page(pmd)
126
127 #endif