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