xref: /linux/arch/powerpc/include/asm/book3s/32/pgalloc.h (revision 417552999d0b6681ac30e117ae890828ca7e46b3)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_BOOK3S_32_PGALLOC_H
3 #define _ASM_POWERPC_BOOK3S_32_PGALLOC_H
4 
5 #include <linux/threads.h>
6 #include <linux/slab.h>
7 
pgd_alloc(struct mm_struct * mm)8 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
9 {
10 	pgd_t *pgd = kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
11 				      pgtable_gfp_flags(mm, GFP_KERNEL));
12 
13 #ifdef CONFIG_PPC_BOOK3S_603
14 	memcpy(pgd + USER_PTRS_PER_PGD, swapper_pg_dir + USER_PTRS_PER_PGD,
15 	       (MAX_PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
16 #endif
17 	return pgd;
18 }
19 
pgd_free(struct mm_struct * mm,pgd_t * pgd)20 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
21 {
22 	kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);
23 }
24 
25 /*
26  * We don't have any real pmd's, and this code never triggers because
27  * the pgd will always be present..
28  */
29 /* #define pmd_alloc_one(mm,address)       ({ BUG(); ((pmd_t *)2); }) */
30 #define pmd_free(mm, x) 		do { } while (0)
31 #define __pmd_free_tlb(tlb,x,a)		do { } while (0)
32 /* #define pgd_populate(mm, pmd, pte)      BUG() */
33 
pmd_populate_kernel(struct mm_struct * mm,pmd_t * pmdp,pte_t * pte)34 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp,
35 				       pte_t *pte)
36 {
37 	*pmdp = __pmd(__pa(pte) | _PMD_PRESENT);
38 }
39 
pmd_populate(struct mm_struct * mm,pmd_t * pmdp,pgtable_t pte_page)40 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmdp,
41 				pgtable_t pte_page)
42 {
43 	*pmdp = __pmd(__pa(pte_page) | _PMD_PRESENT);
44 }
45 
pgtable_free(void * table,unsigned index_size)46 static inline void pgtable_free(void *table, unsigned index_size)
47 {
48 	if (!index_size) {
49 		pte_fragment_free((unsigned long *)table, 0);
50 	} else {
51 		BUG_ON(index_size > MAX_PGTABLE_INDEX_SIZE);
52 		kmem_cache_free(PGT_CACHE(index_size), table);
53 	}
54 }
55 
pgtable_free_tlb(struct mmu_gather * tlb,void * table,int shift)56 static inline void pgtable_free_tlb(struct mmu_gather *tlb,
57 				    void *table, int shift)
58 {
59 	unsigned long pgf = (unsigned long)table;
60 	BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE);
61 	pgf |= shift;
62 	tlb_remove_table(tlb, (void *)pgf);
63 }
64 
__tlb_remove_table(void * _table)65 static inline void __tlb_remove_table(void *_table)
66 {
67 	void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE);
68 	unsigned shift = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE;
69 
70 	pgtable_free(table, shift);
71 }
72 
__pte_free_tlb(struct mmu_gather * tlb,pgtable_t table,unsigned long address)73 static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
74 				  unsigned long address)
75 {
76 	pgtable_free_tlb(tlb, table, 0);
77 }
78 #endif /* _ASM_POWERPC_BOOK3S_32_PGALLOC_H */
79