1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef __ASM_OPENRISC_PGALLOC_H
20#define __ASM_OPENRISC_PGALLOC_H
21
22#include <asm/page.h>
23#include <linux/threads.h>
24#include <linux/mm.h>
25#include <linux/memblock.h>
26
27extern int mem_init_done;
28
29#define pmd_populate_kernel(mm, pmd, pte) \
30 set_pmd(pmd, __pmd(_KERNPG_TABLE + __pa(pte)))
31
32static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
33 struct page *pte)
34{
35 set_pmd(pmd, __pmd(_KERNPG_TABLE +
36 ((unsigned long)page_to_pfn(pte) <<
37 (unsigned long) PAGE_SHIFT)));
38}
39
40
41
42
43static inline pgd_t *pgd_alloc(struct mm_struct *mm)
44{
45 pgd_t *ret = (pgd_t *)__get_free_page(GFP_KERNEL);
46
47 if (ret) {
48 memset(ret, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
49 memcpy(ret + USER_PTRS_PER_PGD,
50 swapper_pg_dir + USER_PTRS_PER_PGD,
51 (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
52
53 }
54 return ret;
55}
56
57#if 0
58
59
60
61
62extern inline pgd_t *pgd_alloc(struct mm_struct *mm)
63{
64 return (pgd_t *)get_zeroed_page(GFP_KERNEL);
65}
66#endif
67
68static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
69{
70 free_page((unsigned long)pgd);
71}
72
73extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address);
74
75static inline struct page *pte_alloc_one(struct mm_struct *mm,
76 unsigned long address)
77{
78 struct page *pte;
79 pte = alloc_pages(GFP_KERNEL, 0);
80 if (!pte)
81 return NULL;
82 clear_page(page_address(pte));
83 if (!pgtable_page_ctor(pte)) {
84 __free_page(pte);
85 return NULL;
86 }
87 return pte;
88}
89
90static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
91{
92 free_page((unsigned long)pte);
93}
94
95static inline void pte_free(struct mm_struct *mm, struct page *pte)
96{
97 pgtable_page_dtor(pte);
98 __free_page(pte);
99}
100
101
102#define __pte_free_tlb(tlb, pte, addr) tlb_remove_page((tlb), (pte))
103#define pmd_pgtable(pmd) pmd_page(pmd)
104
105#define check_pgt_cache() do { } while (0)
106
107#endif
108