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
8extern void mmu_page_ctor(void *page);
9extern void mmu_page_dtor(void *page);
10
11enum m68k_table_types {
12	TABLE_PGD = 0,
13	TABLE_PMD = 0, /* same size as PGD */
14	TABLE_PTE = 1,
15};
16
17extern void init_pointer_table(void *table, int type);
18extern void *get_pointer_table(int type);
19extern 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
27static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
28{
29	return get_pointer_table(TABLE_PTE);
30}
31
32static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
33{
34	free_pointer_table(pte, TABLE_PTE);
35}
36
37static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
38{
39	return get_pointer_table(TABLE_PTE);
40}
41
42static inline void pte_free(struct mm_struct *mm, pgtable_t pgtable)
43{
44	free_pointer_table(pgtable, TABLE_PTE);
45}
46
47static 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
54static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
55{
56	return get_pointer_table(TABLE_PMD);
57}
58
59static inline int pmd_free(struct mm_struct *mm, pmd_t *pmd)
60{
61	return free_pointer_table(pmd, TABLE_PMD);
62}
63
64static 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
71static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
72{
73	free_pointer_table(pgd, TABLE_PGD);
74}
75
76static inline pgd_t *pgd_alloc(struct mm_struct *mm)
77{
78	return get_pointer_table(TABLE_PGD);
79}
80
81
82static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
83{
84	pmd_set(pmd, pte);
85}
86
87static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t page)
88{
89	pmd_set(pmd, page);
90}
91
92static 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