1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * arch/arm/include/asm/pgalloc.h
5 * Copyright (C) 2000-2001 Russell King
7 #ifndef _ASMARM_PGALLOC_H
8 #define _ASMARM_PGALLOC_H
10 #include <linux/pagemap.h>
12 #include <asm/domain.h>
13 #include <asm/pgtable-hwdef.h>
14 #include <asm/processor.h>
15 #include <asm/cacheflush.h>
16 #include <asm/tlbflush.h>
18 #define check_pgt_cache() do { } while (0)
22 #define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
23 #define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL))
25 #ifdef CONFIG_ARM_LPAE
27 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
29 return (pmd_t *)get_zeroed_page(GFP_KERNEL);
32 static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
34 BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
35 free_page((unsigned long)pmd);
38 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
40 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
43 #else /* !CONFIG_ARM_LPAE */
46 * Since we have only two-level page tables, these are trivial
48 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
49 #define pmd_free(mm, pmd) do { } while (0)
50 #define pud_populate(mm,pmd,pte) BUG()
52 #endif /* CONFIG_ARM_LPAE */
54 extern pgd_t *pgd_alloc(struct mm_struct *mm);
55 extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
57 static inline void clean_pte_table(pte_t *pte)
59 clean_dcache_area(pte + PTE_HWTABLE_PTRS, PTE_HWTABLE_SIZE);
63 * Allocate one PTE table.
65 * This actually allocates two hardware PTE tables, but we wrap this up
66 * into one table thus:
79 #define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL
80 #define __HAVE_ARCH_PTE_ALLOC_ONE
81 #include <asm-generic/pgalloc.h>
84 pte_alloc_one_kernel(struct mm_struct *mm)
86 pte_t *pte = __pte_alloc_one_kernel(mm);
95 #define PGTABLE_HIGHMEM __GFP_HIGHMEM
97 #define PGTABLE_HIGHMEM 0
100 static inline pgtable_t
101 pte_alloc_one(struct mm_struct *mm)
105 pte = __pte_alloc_one(mm, GFP_PGTABLE_USER | PGTABLE_HIGHMEM);
108 if (!PageHighMem(pte))
109 clean_pte_table(page_address(pte));
113 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
116 pmdval_t pmdval = (pte + PTE_HWTABLE_OFF) | prot;
117 pmdp[0] = __pmd(pmdval);
118 #ifndef CONFIG_ARM_LPAE
119 pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
121 flush_pmd_entry(pmdp);
125 * Populate the pmdp entry with a pointer to the pte. This pmd is part
126 * of the mm address space.
128 * Ensure that we always set both PMD entries.
131 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
134 * The pmd must be loaded with the physical address of the PTE table
136 __pmd_populate(pmdp, __pa(ptep), _PAGE_KERNEL_TABLE);
140 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
142 extern pmdval_t user_pmd_table;
145 if (__LINUX_ARM_ARCH__ >= 6 && !IS_ENABLED(CONFIG_ARM_LPAE))
146 prot = user_pmd_table;
148 prot = _PAGE_USER_TABLE;
150 __pmd_populate(pmdp, page_to_phys(ptep), prot);
152 #define pmd_pgtable(pmd) pmd_page(pmd)
154 #endif /* CONFIG_MMU */