1 /* SPDX-License-Identifier: GPL-2.0 */
7 #include <linux/threads.h>
8 #include <asm/processor.h>
9 #include <asm/fixmap.h>
11 #include <asm/cache.h>
13 #define __HAVE_ARCH_PMD_ALLOC_ONE
14 #define __HAVE_ARCH_PMD_FREE
15 #define __HAVE_ARCH_PGD_FREE
16 #include <asm-generic/pgalloc.h>
18 /* Allocate the top level pgd (page directory) */
19 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
23 pgd = (pgd_t *) __get_free_pages(GFP_KERNEL, PGD_ORDER);
24 if (unlikely(pgd == NULL))
27 memset(pgd, 0, PAGE_SIZE << PGD_ORDER);
32 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34 free_pages((unsigned long)pgd, PGD_ORDER);
37 #if CONFIG_PGTABLE_LEVELS == 3
39 /* Three Level Page Table Support for pmd's */
41 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
43 set_pud(pud, __pud((PxD_FLAG_PRESENT | PxD_FLAG_VALID) +
44 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT)));
47 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
51 pmd = (pmd_t *)__get_free_pages(GFP_PGTABLE_KERNEL, PMD_TABLE_ORDER);
53 memset ((void *)pmd, 0, PAGE_SIZE << PMD_TABLE_ORDER);
57 static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
59 free_pages((unsigned long)pmd, PMD_TABLE_ORDER);
64 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
66 set_pmd(pmd, __pmd((PxD_FLAG_PRESENT | PxD_FLAG_VALID)
67 + (__u32)(__pa((unsigned long)pte) >> PxD_VALUE_SHIFT)));
70 #define pmd_populate(mm, pmd, pte_page) \
71 pmd_populate_kernel(mm, pmd, page_address(pte_page))