xref: /openbmc/linux/arch/powerpc/include/asm/book3s/32/pgalloc.h (revision 8dd06ef34b6e2f41b29fbf5fc1663780f2524285)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
275a9b8a6SAneesh Kumar K.V #ifndef _ASM_POWERPC_BOOK3S_32_PGALLOC_H
375a9b8a6SAneesh Kumar K.V #define _ASM_POWERPC_BOOK3S_32_PGALLOC_H
4101ad5c6SAneesh Kumar K.V 
5101ad5c6SAneesh Kumar K.V #include <linux/threads.h>
69b081e10SChristophe Leroy #include <linux/slab.h>
7101ad5c6SAneesh Kumar K.V 
pgd_alloc(struct mm_struct * mm)89b081e10SChristophe Leroy static inline pgd_t *pgd_alloc(struct mm_struct *mm)
99b081e10SChristophe Leroy {
10de3b8761SBalbir Singh 	return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
11de3b8761SBalbir Singh 			pgtable_gfp_flags(mm, GFP_KERNEL));
129b081e10SChristophe Leroy }
139b081e10SChristophe Leroy 
pgd_free(struct mm_struct * mm,pgd_t * pgd)149b081e10SChristophe Leroy static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
159b081e10SChristophe Leroy {
169b081e10SChristophe Leroy 	kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);
179b081e10SChristophe Leroy }
18101ad5c6SAneesh Kumar K.V 
19101ad5c6SAneesh Kumar K.V /*
20101ad5c6SAneesh Kumar K.V  * We don't have any real pmd's, and this code never triggers because
21101ad5c6SAneesh Kumar K.V  * the pgd will always be present..
22101ad5c6SAneesh Kumar K.V  */
23101ad5c6SAneesh Kumar K.V /* #define pmd_alloc_one(mm,address)       ({ BUG(); ((pmd_t *)2); }) */
24101ad5c6SAneesh Kumar K.V #define pmd_free(mm, x) 		do { } while (0)
25101ad5c6SAneesh Kumar K.V #define __pmd_free_tlb(tlb,x,a)		do { } while (0)
26101ad5c6SAneesh Kumar K.V /* #define pgd_populate(mm, pmd, pte)      BUG() */
27101ad5c6SAneesh Kumar K.V 
pmd_populate_kernel(struct mm_struct * mm,pmd_t * pmdp,pte_t * pte)28101ad5c6SAneesh Kumar K.V static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp,
29101ad5c6SAneesh Kumar K.V 				       pte_t *pte)
30101ad5c6SAneesh Kumar K.V {
31101ad5c6SAneesh Kumar K.V 	*pmdp = __pmd(__pa(pte) | _PMD_PRESENT);
32101ad5c6SAneesh Kumar K.V }
33101ad5c6SAneesh Kumar K.V 
pmd_populate(struct mm_struct * mm,pmd_t * pmdp,pgtable_t pte_page)34101ad5c6SAneesh Kumar K.V static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmdp,
35101ad5c6SAneesh Kumar K.V 				pgtable_t pte_page)
36101ad5c6SAneesh Kumar K.V {
37*32ea4c14SChristophe Leroy 	*pmdp = __pmd(__pa(pte_page) | _PMD_PRESENT);
38101ad5c6SAneesh Kumar K.V }
39101ad5c6SAneesh Kumar K.V 
pgtable_free(void * table,unsigned index_size)40101ad5c6SAneesh Kumar K.V static inline void pgtable_free(void *table, unsigned index_size)
41101ad5c6SAneesh Kumar K.V {
429b081e10SChristophe Leroy 	if (!index_size) {
43*32ea4c14SChristophe Leroy 		pte_fragment_free((unsigned long *)table, 0);
449b081e10SChristophe Leroy 	} else {
459b081e10SChristophe Leroy 		BUG_ON(index_size > MAX_PGTABLE_INDEX_SIZE);
469b081e10SChristophe Leroy 		kmem_cache_free(PGT_CACHE(index_size), table);
479b081e10SChristophe Leroy 	}
48101ad5c6SAneesh Kumar K.V }
49101ad5c6SAneesh Kumar K.V 
50fadd03c6SAneesh Kumar K.V #define get_hugepd_cache_index(x)  (x)
51101ad5c6SAneesh Kumar K.V 
pgtable_free_tlb(struct mmu_gather * tlb,void * table,int shift)52101ad5c6SAneesh Kumar K.V static inline void pgtable_free_tlb(struct mmu_gather *tlb,
53101ad5c6SAneesh Kumar K.V 				    void *table, int shift)
54101ad5c6SAneesh Kumar K.V {
55101ad5c6SAneesh Kumar K.V 	unsigned long pgf = (unsigned long)table;
56101ad5c6SAneesh Kumar K.V 	BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE);
57101ad5c6SAneesh Kumar K.V 	pgf |= shift;
58101ad5c6SAneesh Kumar K.V 	tlb_remove_table(tlb, (void *)pgf);
59101ad5c6SAneesh Kumar K.V }
60101ad5c6SAneesh Kumar K.V 
__tlb_remove_table(void * _table)61101ad5c6SAneesh Kumar K.V static inline void __tlb_remove_table(void *_table)
62101ad5c6SAneesh Kumar K.V {
63101ad5c6SAneesh Kumar K.V 	void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE);
64101ad5c6SAneesh Kumar K.V 	unsigned shift = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE;
65101ad5c6SAneesh Kumar K.V 
66101ad5c6SAneesh Kumar K.V 	pgtable_free(table, shift);
67101ad5c6SAneesh Kumar K.V }
68101ad5c6SAneesh Kumar K.V 
__pte_free_tlb(struct mmu_gather * tlb,pgtable_t table,unsigned long address)69101ad5c6SAneesh Kumar K.V static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
70101ad5c6SAneesh Kumar K.V 				  unsigned long address)
71101ad5c6SAneesh Kumar K.V {
72*32ea4c14SChristophe Leroy 	pgtable_free_tlb(tlb, table, 0);
73101ad5c6SAneesh Kumar K.V }
7475a9b8a6SAneesh Kumar K.V #endif /* _ASM_POWERPC_BOOK3S_32_PGALLOC_H */
75