2017-11-01 15:07:57 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-04-16 15:20:36 -07:00
|
|
|
#ifndef _ASM_PGALLOC_H
|
|
|
|
|
#define _ASM_PGALLOC_H
|
|
|
|
|
|
|
|
|
|
#include <linux/gfp.h>
|
|
|
|
|
#include <linux/mm.h>
|
|
|
|
|
#include <linux/threads.h>
|
|
|
|
|
#include <asm/processor.h>
|
|
|
|
|
#include <asm/fixmap.h>
|
|
|
|
|
|
|
|
|
|
#include <asm/cache.h>
|
|
|
|
|
|
2020-08-16 17:24:03 +03:00
|
|
|
#define __HAVE_ARCH_PMD_ALLOC_ONE
|
2020-08-06 23:22:39 -07:00
|
|
|
#include <asm-generic/pgalloc.h>
|
2019-07-11 20:58:27 -07:00
|
|
|
|
2021-02-12 16:38:52 +01:00
|
|
|
/* Allocate the top level pgd (page directory) */
|
2005-04-16 15:20:36 -07:00
|
|
|
static inline pgd_t *pgd_alloc(struct mm_struct *mm)
|
|
|
|
|
{
|
2025-01-03 18:44:14 +00:00
|
|
|
return __pgd_alloc(mm, PGD_TABLE_ORDER);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
2015-04-14 15:45:54 -07:00
|
|
|
#if CONFIG_PGTABLE_LEVELS == 3
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
/* Three Level Page Table Support for pmd's */
|
|
|
|
|
|
2019-12-04 16:54:12 -08:00
|
|
|
static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2019-12-04 16:54:12 -08:00
|
|
|
set_pud(pud, __pud((PxD_FLAG_PRESENT | PxD_FLAG_VALID) +
|
|
|
|
|
(__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT)));
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-16 17:24:03 +03:00
|
|
|
static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
|
|
|
|
|
{
|
2025-01-03 18:44:11 +00:00
|
|
|
struct ptdesc *ptdesc;
|
|
|
|
|
gfp_t gfp = GFP_PGTABLE_USER;
|
2021-02-12 16:38:52 +01:00
|
|
|
|
2025-01-03 18:44:11 +00:00
|
|
|
if (mm == &init_mm)
|
|
|
|
|
gfp = GFP_PGTABLE_KERNEL;
|
|
|
|
|
ptdesc = pagetable_alloc(gfp, PMD_TABLE_ORDER);
|
|
|
|
|
if (!ptdesc)
|
|
|
|
|
return NULL;
|
2025-04-08 10:52:11 +01:00
|
|
|
if (!pagetable_pmd_ctor(mm, ptdesc)) {
|
2025-01-03 18:44:11 +00:00
|
|
|
pagetable_free(ptdesc);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return ptdesc_address(ptdesc);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
|
|
|
|
|
{
|
2021-02-12 16:38:52 +01:00
|
|
|
set_pmd(pmd, __pmd((PxD_FLAG_PRESENT | PxD_FLAG_VALID)
|
|
|
|
|
+ (__u32)(__pa((unsigned long)pte) >> PxD_VALUE_SHIFT)));
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define pmd_populate(mm, pmd, pte_page) \
|
|
|
|
|
pmd_populate_kernel(mm, pmd, page_address(pte_page))
|
|
|
|
|
|
|
|
|
|
#endif
|