1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
9 #include <linux/sched.h>
11 #define __HAVE_ARCH_PMD_ALLOC_ONE
12 #define __HAVE_ARCH_PUD_ALLOC_ONE
13 #define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL
14 #include <asm-generic/pgalloc.h>
16 static inline void pmd_populate_kernel(struct mm_struct
*mm
,
17 pmd_t
*pmd
, pte_t
*pte
)
19 set_pmd(pmd
, __pmd((unsigned long)pte
));
22 static inline void pmd_populate(struct mm_struct
*mm
, pmd_t
*pmd
, pgtable_t pte
)
24 set_pmd(pmd
, __pmd((unsigned long)page_address(pte
)));
27 #ifndef __PAGETABLE_PMD_FOLDED
29 static inline void pud_populate(struct mm_struct
*mm
, pud_t
*pud
, pmd_t
*pmd
)
31 set_pud(pud
, __pud((unsigned long)pmd
));
35 #ifndef __PAGETABLE_PUD_FOLDED
37 static inline void p4d_populate(struct mm_struct
*mm
, p4d_t
*p4d
, pud_t
*pud
)
39 set_p4d(p4d
, __p4d((unsigned long)pud
));
42 #endif /* __PAGETABLE_PUD_FOLDED */
44 extern void pagetable_init(void);
46 extern pgd_t
*pgd_alloc(struct mm_struct
*mm
);
48 static inline pte_t
*pte_alloc_one_kernel(struct mm_struct
*mm
)
50 pte_t
*pte
= __pte_alloc_one_kernel(mm
);
58 #define __pte_free_tlb(tlb, pte, address) \
60 pagetable_pte_dtor(page_ptdesc(pte)); \
61 tlb_remove_page_ptdesc((tlb), page_ptdesc(pte)); \
64 #ifndef __PAGETABLE_PMD_FOLDED
66 static inline pmd_t
*pmd_alloc_one(struct mm_struct
*mm
, unsigned long address
)
69 struct ptdesc
*ptdesc
;
71 ptdesc
= pagetable_alloc(GFP_KERNEL_ACCOUNT
, 0);
75 if (!pagetable_pmd_ctor(ptdesc
)) {
76 pagetable_free(ptdesc
);
80 pmd
= ptdesc_address(ptdesc
);
85 #define __pmd_free_tlb(tlb, x, addr) pmd_free((tlb)->mm, x)
89 #ifndef __PAGETABLE_PUD_FOLDED
91 static inline pud_t
*pud_alloc_one(struct mm_struct
*mm
, unsigned long address
)
94 struct ptdesc
*ptdesc
= pagetable_alloc(GFP_KERNEL
& ~__GFP_HIGHMEM
, 0);
98 pagetable_pud_ctor(ptdesc
);
99 pud
= ptdesc_address(ptdesc
);
105 #define __pud_free_tlb(tlb, x, addr) pud_free((tlb)->mm, x)
107 #endif /* __PAGETABLE_PUD_FOLDED */
109 extern pte_t
* __init
populate_kernel_pte(unsigned long addr
);
110 #endif /* _ASM_PGALLOC_H */