Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Based on arch/arm/include/asm/pgalloc.h
0004  *
0005  * Copyright (C) 2000-2001 Russell King
0006  * Copyright (C) 2012 ARM Ltd.
0007  */
0008 #ifndef __ASM_PGALLOC_H
0009 #define __ASM_PGALLOC_H
0010 
0011 #include <asm/pgtable-hwdef.h>
0012 #include <asm/processor.h>
0013 #include <asm/cacheflush.h>
0014 #include <asm/tlbflush.h>
0015 
0016 #define __HAVE_ARCH_PGD_FREE
0017 #include <asm-generic/pgalloc.h>
0018 
0019 #define PGD_SIZE    (PTRS_PER_PGD * sizeof(pgd_t))
0020 
0021 #if CONFIG_PGTABLE_LEVELS > 2
0022 
0023 static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot)
0024 {
0025     set_pud(pudp, __pud(__phys_to_pud_val(pmdp) | prot));
0026 }
0027 
0028 static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmdp)
0029 {
0030     pudval_t pudval = PUD_TYPE_TABLE;
0031 
0032     pudval |= (mm == &init_mm) ? PUD_TABLE_UXN : PUD_TABLE_PXN;
0033     __pud_populate(pudp, __pa(pmdp), pudval);
0034 }
0035 #else
0036 static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot)
0037 {
0038     BUILD_BUG();
0039 }
0040 #endif  /* CONFIG_PGTABLE_LEVELS > 2 */
0041 
0042 #if CONFIG_PGTABLE_LEVELS > 3
0043 
0044 static inline void __p4d_populate(p4d_t *p4dp, phys_addr_t pudp, p4dval_t prot)
0045 {
0046     set_p4d(p4dp, __p4d(__phys_to_p4d_val(pudp) | prot));
0047 }
0048 
0049 static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4dp, pud_t *pudp)
0050 {
0051     p4dval_t p4dval = P4D_TYPE_TABLE;
0052 
0053     p4dval |= (mm == &init_mm) ? P4D_TABLE_UXN : P4D_TABLE_PXN;
0054     __p4d_populate(p4dp, __pa(pudp), p4dval);
0055 }
0056 #else
0057 static inline void __p4d_populate(p4d_t *p4dp, phys_addr_t pudp, p4dval_t prot)
0058 {
0059     BUILD_BUG();
0060 }
0061 #endif  /* CONFIG_PGTABLE_LEVELS > 3 */
0062 
0063 extern pgd_t *pgd_alloc(struct mm_struct *mm);
0064 extern void pgd_free(struct mm_struct *mm, pgd_t *pgdp);
0065 
0066 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t ptep,
0067                   pmdval_t prot)
0068 {
0069     set_pmd(pmdp, __pmd(__phys_to_pmd_val(ptep) | prot));
0070 }
0071 
0072 /*
0073  * Populate the pmdp entry with a pointer to the pte.  This pmd is part
0074  * of the mm address space.
0075  */
0076 static inline void
0077 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
0078 {
0079     VM_BUG_ON(mm && mm != &init_mm);
0080     __pmd_populate(pmdp, __pa(ptep), PMD_TYPE_TABLE | PMD_TABLE_UXN);
0081 }
0082 
0083 static inline void
0084 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
0085 {
0086     VM_BUG_ON(mm == &init_mm);
0087     __pmd_populate(pmdp, page_to_phys(ptep), PMD_TYPE_TABLE | PMD_TABLE_PXN);
0088 }
0089 
0090 #endif