Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_POWERPC_PGALLOC_H
0003 #define _ASM_POWERPC_PGALLOC_H
0004 
0005 #include <linux/mm.h>
0006 
0007 #ifndef MODULE
0008 static inline gfp_t pgtable_gfp_flags(struct mm_struct *mm, gfp_t gfp)
0009 {
0010     if (unlikely(mm == &init_mm))
0011         return gfp;
0012     return gfp | __GFP_ACCOUNT;
0013 }
0014 #else /* !MODULE */
0015 static inline gfp_t pgtable_gfp_flags(struct mm_struct *mm, gfp_t gfp)
0016 {
0017     return gfp | __GFP_ACCOUNT;
0018 }
0019 #endif /* MODULE */
0020 
0021 #define PGALLOC_GFP (GFP_KERNEL | __GFP_ZERO)
0022 
0023 pte_t *pte_fragment_alloc(struct mm_struct *mm, int kernel);
0024 
0025 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
0026 {
0027     return (pte_t *)pte_fragment_alloc(mm, 1);
0028 }
0029 
0030 static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
0031 {
0032     return (pgtable_t)pte_fragment_alloc(mm, 0);
0033 }
0034 
0035 void pte_frag_destroy(void *pte_frag);
0036 void pte_fragment_free(unsigned long *table, int kernel);
0037 
0038 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
0039 {
0040     pte_fragment_free((unsigned long *)pte, 1);
0041 }
0042 
0043 static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
0044 {
0045     pte_fragment_free((unsigned long *)ptepage, 0);
0046 }
0047 
0048 /*
0049  * Functions that deal with pagetables that could be at any level of
0050  * the table need to be passed an "index_size" so they know how to
0051  * handle allocation.  For PTE pages, the allocation size will be
0052  * (2^index_size * sizeof(pointer)) and allocations are drawn from
0053  * the kmem_cache in PGT_CACHE(index_size).
0054  *
0055  * The maximum index size needs to be big enough to allow any
0056  * pagetable sizes we need, but small enough to fit in the low bits of
0057  * any page table pointer.  In other words all pagetables, even tiny
0058  * ones, must be aligned to allow at least enough low 0 bits to
0059  * contain this value.  This value is also used as a mask, so it must
0060  * be one less than a power of two.
0061  */
0062 #define MAX_PGTABLE_INDEX_SIZE  0xf
0063 
0064 extern struct kmem_cache *pgtable_cache[];
0065 #define PGT_CACHE(shift) pgtable_cache[shift]
0066 
0067 #ifdef CONFIG_PPC_BOOK3S
0068 #include <asm/book3s/pgalloc.h>
0069 #else
0070 #include <asm/nohash/pgalloc.h>
0071 #endif
0072 
0073 #endif /* _ASM_POWERPC_PGALLOC_H */