162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef _ASM_POWERPC_PGALLOC_H 362306a36Sopenharmony_ci#define _ASM_POWERPC_PGALLOC_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <linux/mm.h> 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#ifndef MODULE 862306a36Sopenharmony_cistatic inline gfp_t pgtable_gfp_flags(struct mm_struct *mm, gfp_t gfp) 962306a36Sopenharmony_ci{ 1062306a36Sopenharmony_ci if (unlikely(mm == &init_mm)) 1162306a36Sopenharmony_ci return gfp; 1262306a36Sopenharmony_ci return gfp | __GFP_ACCOUNT; 1362306a36Sopenharmony_ci} 1462306a36Sopenharmony_ci#else /* !MODULE */ 1562306a36Sopenharmony_cistatic inline gfp_t pgtable_gfp_flags(struct mm_struct *mm, gfp_t gfp) 1662306a36Sopenharmony_ci{ 1762306a36Sopenharmony_ci return gfp | __GFP_ACCOUNT; 1862306a36Sopenharmony_ci} 1962306a36Sopenharmony_ci#endif /* MODULE */ 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#define PGALLOC_GFP (GFP_KERNEL | __GFP_ZERO) 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_cipte_t *pte_fragment_alloc(struct mm_struct *mm, int kernel); 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_cistatic inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm) 2662306a36Sopenharmony_ci{ 2762306a36Sopenharmony_ci return (pte_t *)pte_fragment_alloc(mm, 1); 2862306a36Sopenharmony_ci} 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_cistatic inline pgtable_t pte_alloc_one(struct mm_struct *mm) 3162306a36Sopenharmony_ci{ 3262306a36Sopenharmony_ci return (pgtable_t)pte_fragment_alloc(mm, 0); 3362306a36Sopenharmony_ci} 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_civoid pte_frag_destroy(void *pte_frag); 3662306a36Sopenharmony_civoid pte_fragment_free(unsigned long *table, int kernel); 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_cistatic inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) 3962306a36Sopenharmony_ci{ 4062306a36Sopenharmony_ci pte_fragment_free((unsigned long *)pte, 1); 4162306a36Sopenharmony_ci} 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_cistatic inline void pte_free(struct mm_struct *mm, pgtable_t ptepage) 4462306a36Sopenharmony_ci{ 4562306a36Sopenharmony_ci pte_fragment_free((unsigned long *)ptepage, 0); 4662306a36Sopenharmony_ci} 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* arch use pte_free_defer() implementation in arch/powerpc/mm/pgtable-frag.c */ 4962306a36Sopenharmony_ci#define pte_free_defer pte_free_defer 5062306a36Sopenharmony_civoid pte_free_defer(struct mm_struct *mm, pgtable_t pgtable); 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci/* 5362306a36Sopenharmony_ci * Functions that deal with pagetables that could be at any level of 5462306a36Sopenharmony_ci * the table need to be passed an "index_size" so they know how to 5562306a36Sopenharmony_ci * handle allocation. For PTE pages, the allocation size will be 5662306a36Sopenharmony_ci * (2^index_size * sizeof(pointer)) and allocations are drawn from 5762306a36Sopenharmony_ci * the kmem_cache in PGT_CACHE(index_size). 5862306a36Sopenharmony_ci * 5962306a36Sopenharmony_ci * The maximum index size needs to be big enough to allow any 6062306a36Sopenharmony_ci * pagetable sizes we need, but small enough to fit in the low bits of 6162306a36Sopenharmony_ci * any page table pointer. In other words all pagetables, even tiny 6262306a36Sopenharmony_ci * ones, must be aligned to allow at least enough low 0 bits to 6362306a36Sopenharmony_ci * contain this value. This value is also used as a mask, so it must 6462306a36Sopenharmony_ci * be one less than a power of two. 6562306a36Sopenharmony_ci */ 6662306a36Sopenharmony_ci#define MAX_PGTABLE_INDEX_SIZE 0xf 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ciextern struct kmem_cache *pgtable_cache[]; 6962306a36Sopenharmony_ci#define PGT_CACHE(shift) pgtable_cache[shift] 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S 7262306a36Sopenharmony_ci#include <asm/book3s/pgalloc.h> 7362306a36Sopenharmony_ci#else 7462306a36Sopenharmony_ci#include <asm/nohash/pgalloc.h> 7562306a36Sopenharmony_ci#endif 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci#endif /* _ASM_POWERPC_PGALLOC_H */ 78