1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_NOHASH_PGALLOC_H
3 #define _ASM_POWERPC_NOHASH_PGALLOC_H
6 #include <linux/slab.h>
8 extern void tlb_remove_table(struct mmu_gather *tlb, void *table);
10 extern void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address);
12 /* 44x etc which is BOOKE not BOOK3E */
13 static inline void tlb_flush_pgtable(struct mmu_gather *tlb,
14 unsigned long address)
18 #endif /* !CONFIG_PPC_BOOK3E_64 */
20 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
22 pgd_t *pgd = kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
23 pgtable_gfp_flags(mm, GFP_KERNEL));
25 #if defined(CONFIG_PPC_8xx) || defined(CONFIG_PPC_BOOK3S_603)
26 memcpy(pgd + USER_PTRS_PER_PGD, swapper_pg_dir + USER_PTRS_PER_PGD,
27 (MAX_PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
32 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34 kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);
38 #include <asm/nohash/64/pgalloc.h>
40 #include <asm/nohash/32/pgalloc.h>
43 static inline void pgtable_free(void *table, int shift)
46 pte_fragment_free((unsigned long *)table, 0);
48 BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE);
49 kmem_cache_free(PGT_CACHE(shift), table);
53 static inline void pgtable_free_tlb(struct mmu_gather *tlb, void *table, int shift)
55 unsigned long pgf = (unsigned long)table;
57 BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE);
59 tlb_remove_table(tlb, (void *)pgf);
62 static inline void __tlb_remove_table(void *_table)
64 void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE);
65 unsigned shift = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE;
67 pgtable_free(table, shift);
70 static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
71 unsigned long address)
73 tlb_flush_pgtable(tlb, address);
74 pgtable_free_tlb(tlb, table, 0);
76 #endif /* _ASM_POWERPC_NOHASH_PGALLOC_H */