1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _ASM_POWERPC_NOHASH_PGALLOC_H 3 #define _ASM_POWERPC_NOHASH_PGALLOC_H 4 5 #include <linux/mm.h> 6 #include <linux/slab.h> 7 8 extern void tlb_remove_table(struct mmu_gather *tlb, void *table); 9 #ifdef CONFIG_PPC64 10 extern void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address); 11 #else 12 /* 44x etc which is BOOKE not BOOK3E */ 13 static inline void tlb_flush_pgtable(struct mmu_gather *tlb, 14 unsigned long address) 15 { 16 17 } 18 #endif /* !CONFIG_PPC_BOOK3E */ 19 20 static inline pgd_t *pgd_alloc(struct mm_struct *mm) 21 { 22 return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE), 23 pgtable_gfp_flags(mm, GFP_KERNEL)); 24 } 25 26 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) 27 { 28 kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd); 29 } 30 31 #ifdef CONFIG_PPC64 32 #include <asm/nohash/64/pgalloc.h> 33 #else 34 #include <asm/nohash/32/pgalloc.h> 35 #endif 36 37 static inline void pgtable_free(void *table, int shift) 38 { 39 if (!shift) { 40 pte_fragment_free((unsigned long *)table, 0); 41 } else { 42 BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE); 43 kmem_cache_free(PGT_CACHE(shift), table); 44 } 45 } 46 47 #define get_hugepd_cache_index(x) (x) 48 49 #ifdef CONFIG_SMP 50 static inline void pgtable_free_tlb(struct mmu_gather *tlb, void *table, int shift) 51 { 52 unsigned long pgf = (unsigned long)table; 53 54 BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE); 55 pgf |= shift; 56 tlb_remove_table(tlb, (void *)pgf); 57 } 58 59 static inline void __tlb_remove_table(void *_table) 60 { 61 void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE); 62 unsigned shift = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE; 63 64 pgtable_free(table, shift); 65 } 66 67 #else 68 static inline void pgtable_free_tlb(struct mmu_gather *tlb, void *table, int shift) 69 { 70 pgtable_free(table, shift); 71 } 72 #endif 73 74 static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table, 75 unsigned long address) 76 { 77 tlb_flush_pgtable(tlb, address); 78 pgtable_free_tlb(tlb, table, 0); 79 } 80 #endif /* _ASM_POWERPC_NOHASH_PGALLOC_H */ 81