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) tlb_remove_ptdesc((tlb), page_ptdesc(pte))
59
60#ifndef __PAGETABLE_PMD_FOLDED
61
62static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
63{
64 pmd_t *pmd;
65 struct ptdesc *ptdesc;
66
67 ptdesc = pagetable_alloc(GFP_KERNEL_ACCOUNT, 0);
68 if (!ptdesc)
69 return NULL;
70
71 if (!pagetable_pmd_ctor(mm, ptdesc)) {
72 pagetable_free(ptdesc);
73 return NULL;
74 }
75
76 pmd = ptdesc_address(ptdesc);
77 pmd_init(pmd);
78 return pmd;
79}
80
81#define __pmd_free_tlb(tlb, x, addr) tlb_remove_ptdesc((tlb), virt_to_ptdesc(x))
82
83#endif
84
85#ifndef __PAGETABLE_PUD_FOLDED
86
87static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
88{
89 pud_t *pud;
90 struct ptdesc *ptdesc = pagetable_alloc(GFP_KERNEL, 0);
91
92 if (!ptdesc)
93 return NULL;
94 pagetable_pud_ctor(ptdesc);
95 pud = ptdesc_address(ptdesc);
96
97 pud_init(pud);
98 return pud;
99}
100
101#define __pud_free_tlb(tlb, x, addr) tlb_remove_ptdesc((tlb), virt_to_ptdesc(x))
102
103#endif /* __PAGETABLE_PUD_FOLDED */
104
105extern pte_t * __init populate_kernel_pte(unsigned long addr);
106#endif /* _ASM_PGALLOC_H */