1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2020 Loongson Technology Corporation Limited
4 */
5#include <linux/export.h>
6#include <linux/mm.h>
7#include <linux/string.h>
8#include <asm/pgalloc.h>
9
10pgd_t *pgd_alloc(struct mm_struct *mm)
11{
12	pgd_t *ret, *init;
13
14	ret = (pgd_t *) __get_free_pages(GFP_KERNEL, PGD_ORDER);
15	if (ret) {
16		init = pgd_offset(&init_mm, 0UL);
17		pgd_init((unsigned long)ret);
18		memcpy(ret + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
19		       (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
20	}
21
22	return ret;
23}
24EXPORT_SYMBOL_GPL(pgd_alloc);
25