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