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 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
22 {
23 	return get_pointer_table(TABLE_PTE);
24 }
25 
26 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
27 {
28 	free_pointer_table(pte, TABLE_PTE);
29 }
30 
31 static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
32 {
33 	return get_pointer_table(TABLE_PTE);
34 }
35 
36 static inline void pte_free(struct mm_struct *mm, pgtable_t pgtable)
37 {
38 	free_pointer_table(pgtable, TABLE_PTE);
39 }
40 
41 static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pgtable,
42 				  unsigned long address)
43 {
44 	free_pointer_table(pgtable, TABLE_PTE);
45 }
46 
47 
48 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
49 {
50 	return get_pointer_table(TABLE_PMD);
51 }
52 
53 static inline int pmd_free(struct mm_struct *mm, pmd_t *pmd)
54 {
55 	return free_pointer_table(pmd, TABLE_PMD);
56 }
57 
58 static inline int __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
59 				 unsigned long address)
60 {
61 	return free_pointer_table(pmd, TABLE_PMD);
62 }
63 
64 
65 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
66 {
67 	free_pointer_table(pgd, TABLE_PGD);
68 }
69 
70 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
71 {
72 	return get_pointer_table(TABLE_PGD);
73 }
74 
75 
76 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
77 {
78 	pmd_set(pmd, pte);
79 }
80 
81 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t page)
82 {
83 	pmd_set(pmd, page);
84 }
85 #define pmd_pgtable(pmd) ((pgtable_t)__pmd_page(pmd))
86 
87 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
88 {
89 	pud_set(pud, pmd);
90 }
91 
92 #endif /* _MOTOROLA_PGALLOC_H */
93