xref: /openbmc/linux/arch/nios2/include/asm/pgalloc.h (revision a2818ee4)
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1994 - 2001, 2003 by Ralf Baechle
7  * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
8  */
9 
10 #ifndef _ASM_NIOS2_PGALLOC_H
11 #define _ASM_NIOS2_PGALLOC_H
12 
13 #include <linux/mm.h>
14 
15 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
16 	pte_t *pte)
17 {
18 	set_pmd(pmd, __pmd((unsigned long)pte));
19 }
20 
21 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
22 	pgtable_t pte)
23 {
24 	set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
25 }
26 #define pmd_pgtable(pmd) pmd_page(pmd)
27 
28 /*
29  * Initialize a new pmd table with invalid pointers.
30  */
31 extern void pmd_init(unsigned long page, unsigned long pagetable);
32 
33 extern pgd_t *pgd_alloc(struct mm_struct *mm);
34 
35 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
36 {
37 	free_pages((unsigned long)pgd, PGD_ORDER);
38 }
39 
40 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
41 {
42 	pte_t *pte;
43 
44 	pte = (pte_t *) __get_free_pages(GFP_KERNEL|__GFP_ZERO, PTE_ORDER);
45 
46 	return pte;
47 }
48 
49 static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
50 {
51 	struct page *pte;
52 
53 	pte = alloc_pages(GFP_KERNEL, PTE_ORDER);
54 	if (pte) {
55 		if (!pgtable_page_ctor(pte)) {
56 			__free_page(pte);
57 			return NULL;
58 		}
59 		clear_highpage(pte);
60 	}
61 	return pte;
62 }
63 
64 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
65 {
66 	free_pages((unsigned long)pte, PTE_ORDER);
67 }
68 
69 static inline void pte_free(struct mm_struct *mm, struct page *pte)
70 {
71 	pgtable_page_dtor(pte);
72 	__free_pages(pte, PTE_ORDER);
73 }
74 
75 #define __pte_free_tlb(tlb, pte, addr)				\
76 	do {							\
77 		pgtable_page_dtor(pte);				\
78 		tlb_remove_page((tlb), (pte));			\
79 	} while (0)
80 
81 #define check_pgt_cache()	do { } while (0)
82 
83 #endif /* _ASM_NIOS2_PGALLOC_H */
84