]> Git Repo - linux.git/blob - arch/loongarch/include/asm/pgalloc.h
Linux 6.14-rc3
[linux.git] / arch / loongarch / include / asm / pgalloc.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4  */
5 #ifndef _ASM_PGALLOC_H
6 #define _ASM_PGALLOC_H
7
8 #include <linux/mm.h>
9 #include <linux/sched.h>
10
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>
15
16 static inline void pmd_populate_kernel(struct mm_struct *mm,
17                                        pmd_t *pmd, pte_t *pte)
18 {
19         set_pmd(pmd, __pmd((unsigned long)pte));
20 }
21
22 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t pte)
23 {
24         set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
25 }
26
27 #ifndef __PAGETABLE_PMD_FOLDED
28
29 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
30 {
31         set_pud(pud, __pud((unsigned long)pmd));
32 }
33 #endif
34
35 #ifndef __PAGETABLE_PUD_FOLDED
36
37 static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4d, pud_t *pud)
38 {
39         set_p4d(p4d, __p4d((unsigned long)pud));
40 }
41
42 #endif /* __PAGETABLE_PUD_FOLDED */
43
44 extern void pagetable_init(void);
45
46 extern pgd_t *pgd_alloc(struct mm_struct *mm);
47
48 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
49 {
50         pte_t *pte = __pte_alloc_one_kernel(mm);
51
52         if (pte)
53                 kernel_pte_init(pte);
54
55         return pte;
56 }
57
58 #define __pte_free_tlb(tlb, pte, address)                       \
59 do {                                                            \
60         pagetable_dtor(page_ptdesc(pte));                       \
61         tlb_remove_page_ptdesc((tlb), page_ptdesc(pte));        \
62 } while (0)
63
64 #ifndef __PAGETABLE_PMD_FOLDED
65
66 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
67 {
68         pmd_t *pmd;
69         struct ptdesc *ptdesc;
70
71         ptdesc = pagetable_alloc(GFP_KERNEL_ACCOUNT, 0);
72         if (!ptdesc)
73                 return NULL;
74
75         if (!pagetable_pmd_ctor(ptdesc)) {
76                 pagetable_free(ptdesc);
77                 return NULL;
78         }
79
80         pmd = ptdesc_address(ptdesc);
81         pmd_init(pmd);
82         return pmd;
83 }
84
85 #define __pmd_free_tlb(tlb, x, addr)    pmd_free((tlb)->mm, x)
86
87 #endif
88
89 #ifndef __PAGETABLE_PUD_FOLDED
90
91 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
92 {
93         pud_t *pud;
94         struct ptdesc *ptdesc = pagetable_alloc(GFP_KERNEL & ~__GFP_HIGHMEM, 0);
95
96         if (!ptdesc)
97                 return NULL;
98         pagetable_pud_ctor(ptdesc);
99         pud = ptdesc_address(ptdesc);
100
101         pud_init(pud);
102         return pud;
103 }
104
105 #define __pud_free_tlb(tlb, x, addr)    pud_free((tlb)->mm, x)
106
107 #endif /* __PAGETABLE_PUD_FOLDED */
108
109 extern pte_t * __init populate_kernel_pte(unsigned long addr);
110 #endif /* _ASM_PGALLOC_H */
This page took 0.0331129999999999 seconds and 4 git commands to generate.