Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
16static 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
22static 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
29static 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
37static 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
44extern void pagetable_init(void);
45
46extern pgd_t *pgd_alloc(struct mm_struct *mm);
47
48static 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 tlb_remove_ptdesc((tlb), page_ptdesc(pte))
60
61#ifndef __PAGETABLE_PMD_FOLDED
62
63static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
64{
65 pmd_t *pmd;
66 struct ptdesc *ptdesc;
67
68 ptdesc = pagetable_alloc(GFP_KERNEL_ACCOUNT, 0);
69 if (!ptdesc)
70 return NULL;
71
72 if (!pagetable_pmd_ctor(mm, ptdesc)) {
73 pagetable_free(ptdesc);
74 return NULL;
75 }
76
77 pmd = ptdesc_address(ptdesc);
78 pmd_init(pmd);
79 return pmd;
80}
81
82#define __pmd_free_tlb(tlb, x, addr) pmd_free((tlb)->mm, x)
83
84#endif
85
86#ifndef __PAGETABLE_PUD_FOLDED
87
88static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
89{
90 pud_t *pud;
91 struct ptdesc *ptdesc = pagetable_alloc(GFP_KERNEL, 0);
92
93 if (!ptdesc)
94 return NULL;
95 pagetable_pud_ctor(ptdesc);
96 pud = ptdesc_address(ptdesc);
97
98 pud_init(pud);
99 return pud;
100}
101
102#define __pud_free_tlb(tlb, x, addr) pud_free((tlb)->mm, x)
103
104#endif /* __PAGETABLE_PUD_FOLDED */
105
106extern pte_t * __init populate_kernel_pte(unsigned long addr);
107#endif /* _ASM_PGALLOC_H */