1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * OpenRISC ioremap.c
4 *
5 * Linux architectural port borrowing liberally from similar works of
6 * others.  All original copyrights apply as per the original source
7 * declaration.
8 *
9 * Modifications for the OpenRISC architecture:
10 * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
11 * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
12 */
13
14#include <linux/vmalloc.h>
15#include <linux/io.h>
16#include <linux/pgtable.h>
17#include <asm/pgalloc.h>
18#include <asm/fixmap.h>
19#include <asm/bug.h>
20#include <linux/sched.h>
21#include <asm/tlbflush.h>
22
23extern int mem_init_done;
24
25/*
26 * OK, this one's a bit tricky... ioremap can get called before memory is
27 * initialized (early serial console does this) and will want to alloc a page
28 * for its mapping.  No userspace pages will ever get allocated before memory
29 * is initialized so this applies only to kernel pages.  In the event that
30 * this is called before memory is initialized we allocate the page using
31 * the memblock infrastructure.
32 */
33
34pte_t __ref *pte_alloc_one_kernel(struct mm_struct *mm)
35{
36	pte_t *pte;
37
38	if (likely(mem_init_done)) {
39		pte = (pte_t *)get_zeroed_page(GFP_KERNEL);
40	} else {
41		pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
42		if (!pte)
43			panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
44			      __func__, PAGE_SIZE, PAGE_SIZE);
45	}
46
47	return pte;
48}
49