xref: /openbmc/linux/arch/powerpc/include/asm/pgalloc.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_PGALLOC_H
3b8b572e1SStephen Rothwell #define _ASM_POWERPC_PGALLOC_H
4b8b572e1SStephen Rothwell 
50186f47eSKumar Gala #include <linux/mm.h>
60186f47eSKumar Gala 
7de3b8761SBalbir Singh #ifndef MODULE
pgtable_gfp_flags(struct mm_struct * mm,gfp_t gfp)8de3b8761SBalbir Singh static inline gfp_t pgtable_gfp_flags(struct mm_struct *mm, gfp_t gfp)
9de3b8761SBalbir Singh {
10de3b8761SBalbir Singh 	if (unlikely(mm == &init_mm))
11de3b8761SBalbir Singh 		return gfp;
12de3b8761SBalbir Singh 	return gfp | __GFP_ACCOUNT;
13de3b8761SBalbir Singh }
14de3b8761SBalbir Singh #else /* !MODULE */
pgtable_gfp_flags(struct mm_struct * mm,gfp_t gfp)15de3b8761SBalbir Singh static inline gfp_t pgtable_gfp_flags(struct mm_struct *mm, gfp_t gfp)
16de3b8761SBalbir Singh {
17de3b8761SBalbir Singh 	return gfp | __GFP_ACCOUNT;
18de3b8761SBalbir Singh }
19de3b8761SBalbir Singh #endif /* MODULE */
20de3b8761SBalbir Singh 
2175f296d9SLevin, Alexander (Sasha Levin) #define PGALLOC_GFP (GFP_KERNEL | __GFP_ZERO)
225b6c133eSMichael Ellerman 
23dc096864SChristophe Leroy pte_t *pte_fragment_alloc(struct mm_struct *mm, int kernel);
24dc096864SChristophe Leroy 
pte_alloc_one_kernel(struct mm_struct * mm)25dc096864SChristophe Leroy static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
26dc096864SChristophe Leroy {
27dc096864SChristophe Leroy 	return (pte_t *)pte_fragment_alloc(mm, 1);
28dc096864SChristophe Leroy }
29dc096864SChristophe Leroy 
pte_alloc_one(struct mm_struct * mm)30dc096864SChristophe Leroy static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
31dc096864SChristophe Leroy {
32dc096864SChristophe Leroy 	return (pgtable_t)pte_fragment_alloc(mm, 0);
33dc096864SChristophe Leroy }
34dc096864SChristophe Leroy 
35dc096864SChristophe Leroy void pte_frag_destroy(void *pte_frag);
36dc096864SChristophe Leroy void pte_fragment_free(unsigned long *table, int kernel);
37dc096864SChristophe Leroy 
pte_free_kernel(struct mm_struct * mm,pte_t * pte)38dc096864SChristophe Leroy static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
39dc096864SChristophe Leroy {
40dc096864SChristophe Leroy 	pte_fragment_free((unsigned long *)pte, 1);
41dc096864SChristophe Leroy }
42dc096864SChristophe Leroy 
pte_free(struct mm_struct * mm,pgtable_t ptepage)43dc096864SChristophe Leroy static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
44dc096864SChristophe Leroy {
45dc096864SChristophe Leroy 	pte_fragment_free((unsigned long *)ptepage, 0);
46dc096864SChristophe Leroy }
47dc096864SChristophe Leroy 
48*32cc0b7cSHugh Dickins /* arch use pte_free_defer() implementation in arch/powerpc/mm/pgtable-frag.c */
49*32cc0b7cSHugh Dickins #define pte_free_defer pte_free_defer
50*32cc0b7cSHugh Dickins void pte_free_defer(struct mm_struct *mm, pgtable_t pgtable);
51*32cc0b7cSHugh Dickins 
52e80789a3SChristophe Leroy /*
53e80789a3SChristophe Leroy  * Functions that deal with pagetables that could be at any level of
54e80789a3SChristophe Leroy  * the table need to be passed an "index_size" so they know how to
55e80789a3SChristophe Leroy  * handle allocation.  For PTE pages, the allocation size will be
56e80789a3SChristophe Leroy  * (2^index_size * sizeof(pointer)) and allocations are drawn from
57e80789a3SChristophe Leroy  * the kmem_cache in PGT_CACHE(index_size).
58e80789a3SChristophe Leroy  *
59e80789a3SChristophe Leroy  * The maximum index size needs to be big enough to allow any
60e80789a3SChristophe Leroy  * pagetable sizes we need, but small enough to fit in the low bits of
61e80789a3SChristophe Leroy  * any page table pointer.  In other words all pagetables, even tiny
62e80789a3SChristophe Leroy  * ones, must be aligned to allow at least enough low 0 bits to
63e80789a3SChristophe Leroy  * contain this value.  This value is also used as a mask, so it must
64e80789a3SChristophe Leroy  * be one less than a power of two.
65e80789a3SChristophe Leroy  */
66e80789a3SChristophe Leroy #define MAX_PGTABLE_INDEX_SIZE	0xf
67e80789a3SChristophe Leroy 
68e80789a3SChristophe Leroy extern struct kmem_cache *pgtable_cache[];
69e80789a3SChristophe Leroy #define PGT_CACHE(shift) pgtable_cache[shift]
70e80789a3SChristophe Leroy 
7175a9b8a6SAneesh Kumar K.V #ifdef CONFIG_PPC_BOOK3S
7275a9b8a6SAneesh Kumar K.V #include <asm/book3s/pgalloc.h>
73b8b572e1SStephen Rothwell #else
7475a9b8a6SAneesh Kumar K.V #include <asm/nohash/pgalloc.h>
75b8b572e1SStephen Rothwell #endif
76b8b572e1SStephen Rothwell 
77b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PGALLOC_H */
78