1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _MOTOROLA_PGALLOC_H
3 #define _MOTOROLA_PGALLOC_H
4 
5 #include <asm/tlb.h>
6 #include <asm/tlbflush.h>
7 
8 extern void mmu_page_ctor(void *page);
9 extern void mmu_page_dtor(void *page);
10 
11 enum m68k_table_types {
12 	TABLE_PGD = 0,
13 	TABLE_PMD = 0, /* same size as PGD */
14 	TABLE_PTE = 1,
15 };
16 
17 extern void init_pointer_table(void *table, int type);
18 extern void *get_pointer_table(int type);
19 extern int free_pointer_table(void *table, int type);
20 
21 /*
22  * Allocate and free page tables. The xxx_kernel() versions are
23  * used to allocate a kernel page table - this turns on ASN bits
24  * if any.
25  */
26 
pte_alloc_one_kernel(struct mm_struct * mm)27 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
28 {
29 	return get_pointer_table(TABLE_PTE);
30 }
31 
pte_free_kernel(struct mm_struct * mm,pte_t * pte)32 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
33 {
34 	free_pointer_table(pte, TABLE_PTE);
35 }
36 
pte_alloc_one(struct mm_struct * mm)37 static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
38 {
39 	return get_pointer_table(TABLE_PTE);
40 }
41 
pte_free(struct mm_struct * mm,pgtable_t pgtable)42 static inline void pte_free(struct mm_struct *mm, pgtable_t pgtable)
43 {
44 	free_pointer_table(pgtable, TABLE_PTE);
45 }
46 
__pte_free_tlb(struct mmu_gather * tlb,pgtable_t pgtable,unsigned long address)47 static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pgtable,
48 				  unsigned long address)
49 {
50 	free_pointer_table(pgtable, TABLE_PTE);
51 }
52 
53 
pmd_alloc_one(struct mm_struct * mm,unsigned long address)54 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
55 {
56 	return get_pointer_table(TABLE_PMD);
57 }
58 
pmd_free(struct mm_struct * mm,pmd_t * pmd)59 static inline int pmd_free(struct mm_struct *mm, pmd_t *pmd)
60 {
61 	return free_pointer_table(pmd, TABLE_PMD);
62 }
63 
__pmd_free_tlb(struct mmu_gather * tlb,pmd_t * pmd,unsigned long address)64 static inline int __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
65 				 unsigned long address)
66 {
67 	return free_pointer_table(pmd, TABLE_PMD);
68 }
69 
70 
pgd_free(struct mm_struct * mm,pgd_t * pgd)71 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
72 {
73 	free_pointer_table(pgd, TABLE_PGD);
74 }
75 
pgd_alloc(struct mm_struct * mm)76 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
77 {
78 	return get_pointer_table(TABLE_PGD);
79 }
80 
81 
pmd_populate_kernel(struct mm_struct * mm,pmd_t * pmd,pte_t * pte)82 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
83 {
84 	pmd_set(pmd, pte);
85 }
86 
pmd_populate(struct mm_struct * mm,pmd_t * pmd,pgtable_t page)87 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t page)
88 {
89 	pmd_set(pmd, page);
90 }
91 
pud_populate(struct mm_struct * mm,pud_t * pud,pmd_t * pmd)92 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
93 {
94 	pud_set(pud, pmd);
95 }
96 
97 #endif /* _MOTOROLA_PGALLOC_H */
98