xref: /linux/arch/powerpc/include/asm/pgalloc.h (revision dc096864ba784c2d3d10480d71f14a53f40f997c)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_PGALLOC_H
3 #define _ASM_POWERPC_PGALLOC_H
4 
5 #include <linux/mm.h>
6 
7 #ifndef MODULE
8 static inline gfp_t pgtable_gfp_flags(struct mm_struct *mm, gfp_t gfp)
9 {
10 	if (unlikely(mm == &init_mm))
11 		return gfp;
12 	return gfp | __GFP_ACCOUNT;
13 }
14 #else /* !MODULE */
15 static inline gfp_t pgtable_gfp_flags(struct mm_struct *mm, gfp_t gfp)
16 {
17 	return gfp | __GFP_ACCOUNT;
18 }
19 #endif /* MODULE */
20 
21 #define PGALLOC_GFP (GFP_KERNEL | __GFP_ZERO)
22 
23 pte_t *pte_fragment_alloc(struct mm_struct *mm, int kernel);
24 
25 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
26 {
27 	return (pte_t *)pte_fragment_alloc(mm, 1);
28 }
29 
30 static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
31 {
32 	return (pgtable_t)pte_fragment_alloc(mm, 0);
33 }
34 
35 void pte_frag_destroy(void *pte_frag);
36 void pte_fragment_free(unsigned long *table, int kernel);
37 
38 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
39 {
40 	pte_fragment_free((unsigned long *)pte, 1);
41 }
42 
43 static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
44 {
45 	pte_fragment_free((unsigned long *)ptepage, 0);
46 }
47 
48 #ifdef CONFIG_PPC_BOOK3S
49 #include <asm/book3s/pgalloc.h>
50 #else
51 #include <asm/nohash/pgalloc.h>
52 #endif
53 
54 #endif /* _ASM_POWERPC_PGALLOC_H */
55