1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#ifndef _ASM_ARC_PGALLOC_H
33#define _ASM_ARC_PGALLOC_H
34
35#include <linux/mm.h>
36#include <linux/log2.h>
37
38static inline void
39pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
40{
41 pmd_set(pmd, pte);
42}
43
44static inline void
45pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t ptep)
46{
47 pmd_set(pmd, (pte_t *) ptep);
48}
49
50static inline int __get_order_pgd(void)
51{
52 return get_order(PTRS_PER_PGD * sizeof(pgd_t));
53}
54
55static inline pgd_t *pgd_alloc(struct mm_struct *mm)
56{
57 int num, num2;
58 pgd_t *ret = (pgd_t *) __get_free_pages(GFP_KERNEL, __get_order_pgd());
59
60 if (ret) {
61 num = USER_PTRS_PER_PGD + USER_KERNEL_GUTTER / PGDIR_SIZE;
62 memzero(ret, num * sizeof(pgd_t));
63
64 num2 = VMALLOC_SIZE / PGDIR_SIZE;
65 memcpy(ret + num, swapper_pg_dir + num, num2 * sizeof(pgd_t));
66
67 memzero(ret + num + num2,
68 (PTRS_PER_PGD - num - num2) * sizeof(pgd_t));
69
70 }
71 return ret;
72}
73
74static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
75{
76 free_pages((unsigned long)pgd, __get_order_pgd());
77}
78
79
80
81
82
83
84
85
86
87
88static inline int __get_order_pte(void)
89{
90 return get_order(PTRS_PER_PTE * sizeof(pte_t));
91}
92
93static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
94 unsigned long address)
95{
96 pte_t *pte;
97
98 pte = (pte_t *) __get_free_pages(GFP_KERNEL | __GFP_ZERO,
99 __get_order_pte());
100
101 return pte;
102}
103
104static inline pgtable_t
105pte_alloc_one(struct mm_struct *mm, unsigned long address)
106{
107 pgtable_t pte_pg;
108 struct page *page;
109
110 pte_pg = (pgtable_t)__get_free_pages(GFP_KERNEL, __get_order_pte());
111 if (!pte_pg)
112 return 0;
113 memzero((void *)pte_pg, PTRS_PER_PTE * sizeof(pte_t));
114 page = virt_to_page(pte_pg);
115 if (!pgtable_page_ctor(page)) {
116 __free_page(page);
117 return 0;
118 }
119
120 return pte_pg;
121}
122
123static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
124{
125 free_pages((unsigned long)pte, __get_order_pte());
126}
127
128static inline void pte_free(struct mm_struct *mm, pgtable_t ptep)
129{
130 pgtable_page_dtor(virt_to_page(ptep));
131 free_pages((unsigned long)ptep, __get_order_pte());
132}
133
134#define __pte_free_tlb(tlb, pte, addr) pte_free((tlb)->mm, pte)
135
136#define check_pgt_cache() do { } while (0)
137#define pmd_pgtable(pmd) ((pgtable_t) pmd_page_vaddr(pmd))
138
139#endif
140