1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 2 /* 3 * Based on arch/arm/include/asm/pgalloc.h 4 * 5 * Copyright (C) 2000-2001 Russell King 6 * Copyright (C) 2012 ARM Ltd. 7 */ 8 #ifndef __ASM_PGALLOC_H 9 #define __ASM_PGALLOC_H 10 11 #include <asm/pgtable-hwdef.h> 12 #include <asm/processor.h> 13 #include <asm/cacheflush.h> 14 #include <asm/tlbflush.h> 15 16 #define __HAVE_ARCH_PGD_FREE 17 #define __HAVE_ARCH_PUD_FREE 18 #include <asm-generic/pgalloc.h> 19 20 #define PGD_SIZE (PTRS_PER_PGD * sizeof 21 22 #if CONFIG_PGTABLE_LEVELS > 2 23 24 static inline void __pud_populate(pud_t *pudp, 25 { 26 set_pud(pudp, __pud(__phys_to_pud_val( 27 } 28 29 static inline void pud_populate(struct mm_stru 30 { 31 pudval_t pudval = PUD_TYPE_TABLE; 32 33 pudval |= (mm == &init_mm) ? PUD_TABLE 34 __pud_populate(pudp, __pa(pmdp), pudva 35 } 36 #else 37 static inline void __pud_populate(pud_t *pudp, 38 { 39 BUILD_BUG(); 40 } 41 #endif /* CONFIG_PGTABLE_LEVELS > 2 */ 42 43 #if CONFIG_PGTABLE_LEVELS > 3 44 45 static inline void __p4d_populate(p4d_t *p4dp, 46 { 47 if (pgtable_l4_enabled()) 48 set_p4d(p4dp, __p4d(__phys_to_ 49 } 50 51 static inline void p4d_populate(struct mm_stru 52 { 53 p4dval_t p4dval = P4D_TYPE_TABLE; 54 55 p4dval |= (mm == &init_mm) ? P4D_TABLE 56 __p4d_populate(p4dp, __pa(pudp), p4dva 57 } 58 59 static inline void pud_free(struct mm_struct * 60 { 61 if (!pgtable_l4_enabled()) 62 return; 63 __pud_free(mm, pud); 64 } 65 #else 66 static inline void __p4d_populate(p4d_t *p4dp, 67 { 68 BUILD_BUG(); 69 } 70 #endif /* CONFIG_PGTABLE_LEVELS > 3 */ 71 72 #if CONFIG_PGTABLE_LEVELS > 4 73 74 static inline void __pgd_populate(pgd_t *pgdp, 75 { 76 if (pgtable_l5_enabled()) 77 set_pgd(pgdp, __pgd(__phys_to_ 78 } 79 80 static inline void pgd_populate(struct mm_stru 81 { 82 pgdval_t pgdval = PGD_TYPE_TABLE; 83 84 pgdval |= (mm == &init_mm) ? PGD_TABLE 85 __pgd_populate(pgdp, __pa(p4dp), pgdva 86 } 87 88 static inline p4d_t *p4d_alloc_one(struct mm_s 89 { 90 gfp_t gfp = GFP_PGTABLE_USER; 91 92 if (mm == &init_mm) 93 gfp = GFP_PGTABLE_KERNEL; 94 return (p4d_t *)get_zeroed_page(gfp); 95 } 96 97 static inline void p4d_free(struct mm_struct * 98 { 99 if (!pgtable_l5_enabled()) 100 return; 101 BUG_ON((unsigned long)p4d & (PAGE_SIZE 102 free_page((unsigned long)p4d); 103 } 104 105 #define __p4d_free_tlb(tlb, p4d, addr) p4d_fr 106 #else 107 static inline void __pgd_populate(pgd_t *pgdp, 108 { 109 BUILD_BUG(); 110 } 111 #endif /* CONFIG_PGTABLE_LEVELS > 4 */ 112 113 extern pgd_t *pgd_alloc(struct mm_struct *mm); 114 extern void pgd_free(struct mm_struct *mm, pgd 115 116 static inline void __pmd_populate(pmd_t *pmdp, 117 pmdval_t pro 118 { 119 set_pmd(pmdp, __pmd(__phys_to_pmd_val( 120 } 121 122 /* 123 * Populate the pmdp entry with a pointer to t 124 * of the mm address space. 125 */ 126 static inline void 127 pmd_populate_kernel(struct mm_struct *mm, pmd_ 128 { 129 VM_BUG_ON(mm && mm != &init_mm); 130 __pmd_populate(pmdp, __pa(ptep), PMD_T 131 } 132 133 static inline void 134 pmd_populate(struct mm_struct *mm, pmd_t *pmdp 135 { 136 VM_BUG_ON(mm == &init_mm); 137 __pmd_populate(pmdp, page_to_phys(ptep 138 } 139 140 #endif 141
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.