Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / arch / loongarch / include / asm / pgalloc.h
bloba7b9c9e73593d2e4a7d79134ad3b70f3415787c4
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
8 #include <linux/mm.h>
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));
33 #endif
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);
52 if (pte)
53 kernel_pte_init(pte);
55 return pte;
58 #define __pte_free_tlb(tlb, pte, address) \
59 do { \
60 pagetable_pte_dtor(page_ptdesc(pte)); \
61 tlb_remove_page_ptdesc((tlb), page_ptdesc(pte)); \
62 } while (0)
64 #ifndef __PAGETABLE_PMD_FOLDED
66 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
68 pmd_t *pmd;
69 struct ptdesc *ptdesc;
71 ptdesc = pagetable_alloc(GFP_KERNEL_ACCOUNT, 0);
72 if (!ptdesc)
73 return NULL;
75 if (!pagetable_pmd_ctor(ptdesc)) {
76 pagetable_free(ptdesc);
77 return NULL;
80 pmd = ptdesc_address(ptdesc);
81 pmd_init(pmd);
82 return pmd;
85 #define __pmd_free_tlb(tlb, x, addr) pmd_free((tlb)->mm, x)
87 #endif
89 #ifndef __PAGETABLE_PUD_FOLDED
91 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
93 pud_t *pud;
94 struct ptdesc *ptdesc = pagetable_alloc(GFP_KERNEL & ~__GFP_HIGHMEM, 0);
96 if (!ptdesc)
97 return NULL;
98 pagetable_pud_ctor(ptdesc);
99 pud = ptdesc_address(ptdesc);
101 pud_init(pud);
102 return pud;
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 */