18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_NOHASH_PGALLOC_H 38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_NOHASH_PGALLOC_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/mm.h> 68c2ecf20Sopenharmony_ci#include <linux/slab.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciextern void tlb_remove_table(struct mmu_gather *tlb, void *table); 98c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC64 108c2ecf20Sopenharmony_ciextern void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address); 118c2ecf20Sopenharmony_ci#else 128c2ecf20Sopenharmony_ci/* 44x etc which is BOOKE not BOOK3E */ 138c2ecf20Sopenharmony_cistatic inline void tlb_flush_pgtable(struct mmu_gather *tlb, 148c2ecf20Sopenharmony_ci unsigned long address) 158c2ecf20Sopenharmony_ci{ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci} 188c2ecf20Sopenharmony_ci#endif /* !CONFIG_PPC_BOOK3E */ 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistatic inline pgd_t *pgd_alloc(struct mm_struct *mm) 218c2ecf20Sopenharmony_ci{ 228c2ecf20Sopenharmony_ci return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE), 238c2ecf20Sopenharmony_ci pgtable_gfp_flags(mm, GFP_KERNEL)); 248c2ecf20Sopenharmony_ci} 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistatic inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd); 298c2ecf20Sopenharmony_ci} 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC64 328c2ecf20Sopenharmony_ci#include <asm/nohash/64/pgalloc.h> 338c2ecf20Sopenharmony_ci#else 348c2ecf20Sopenharmony_ci#include <asm/nohash/32/pgalloc.h> 358c2ecf20Sopenharmony_ci#endif 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic inline void pgtable_free(void *table, int shift) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci if (!shift) { 408c2ecf20Sopenharmony_ci pte_fragment_free((unsigned long *)table, 0); 418c2ecf20Sopenharmony_ci } else { 428c2ecf20Sopenharmony_ci BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE); 438c2ecf20Sopenharmony_ci kmem_cache_free(PGT_CACHE(shift), table); 448c2ecf20Sopenharmony_ci } 458c2ecf20Sopenharmony_ci} 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define get_hugepd_cache_index(x) (x) 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistatic inline void pgtable_free_tlb(struct mmu_gather *tlb, void *table, int shift) 508c2ecf20Sopenharmony_ci{ 518c2ecf20Sopenharmony_ci unsigned long pgf = (unsigned long)table; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE); 548c2ecf20Sopenharmony_ci pgf |= shift; 558c2ecf20Sopenharmony_ci tlb_remove_table(tlb, (void *)pgf); 568c2ecf20Sopenharmony_ci} 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistatic inline void __tlb_remove_table(void *_table) 598c2ecf20Sopenharmony_ci{ 608c2ecf20Sopenharmony_ci void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE); 618c2ecf20Sopenharmony_ci unsigned shift = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci pgtable_free(table, shift); 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table, 678c2ecf20Sopenharmony_ci unsigned long address) 688c2ecf20Sopenharmony_ci{ 698c2ecf20Sopenharmony_ci tlb_flush_pgtable(tlb, address); 708c2ecf20Sopenharmony_ci pgtable_free_tlb(tlb, table, 0); 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_NOHASH_PGALLOC_H */ 73