2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2011-06-04 16:06:11 +08:00
|
|
|
/*
|
|
|
|
* OpenRISC ioremap.c
|
|
|
|
*
|
|
|
|
* Linux architectural port borrowing liberally from similar works of
|
|
|
|
* others. All original copyrights apply as per the original source
|
|
|
|
* declaration.
|
|
|
|
*
|
|
|
|
* Modifications for the OpenRISC architecture:
|
|
|
|
* Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
|
|
|
|
* Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/kmap_types.h>
|
|
|
|
#include <asm/fixmap.h>
|
|
|
|
#include <asm/bug.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
|
|
|
|
extern int mem_init_done;
|
|
|
|
|
|
|
|
static unsigned int fixmaps_used __initdata;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remap an arbitrary physical address space into the kernel virtual
|
|
|
|
* address space. Needed when the kernel wants to access high addresses
|
|
|
|
* directly.
|
|
|
|
*
|
|
|
|
* NOTE! We need to allow non-page-aligned mappings too: we will obviously
|
|
|
|
* have to convert them into an offset in a page-aligned mapping, but the
|
|
|
|
* caller shouldn't need to know that small detail.
|
|
|
|
*/
|
2019-08-17 15:32:32 +08:00
|
|
|
void __iomem *__ref ioremap(phys_addr_t addr, unsigned long size)
|
2011-06-04 16:06:11 +08:00
|
|
|
{
|
|
|
|
phys_addr_t p;
|
|
|
|
unsigned long v;
|
|
|
|
unsigned long offset, last_addr;
|
|
|
|
struct vm_struct *area = NULL;
|
|
|
|
|
|
|
|
/* Don't allow wraparound or zero size */
|
|
|
|
last_addr = addr + size - 1;
|
|
|
|
if (!size || last_addr < addr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mappings have to be page-aligned
|
|
|
|
*/
|
|
|
|
offset = addr & ~PAGE_MASK;
|
|
|
|
p = addr & PAGE_MASK;
|
|
|
|
size = PAGE_ALIGN(last_addr + 1) - p;
|
|
|
|
|
|
|
|
if (likely(mem_init_done)) {
|
|
|
|
area = get_vm_area(size, VM_IOREMAP);
|
|
|
|
if (!area)
|
|
|
|
return NULL;
|
|
|
|
v = (unsigned long)area->addr;
|
|
|
|
} else {
|
|
|
|
if ((fixmaps_used + (size >> PAGE_SHIFT)) > FIX_N_IOREMAPS)
|
|
|
|
return NULL;
|
|
|
|
v = fix_to_virt(FIX_IOREMAP_BEGIN + fixmaps_used);
|
|
|
|
fixmaps_used += (size >> PAGE_SHIFT);
|
|
|
|
}
|
|
|
|
|
2019-08-17 15:32:32 +08:00
|
|
|
if (ioremap_page_range(v, v + size, p,
|
|
|
|
__pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_CI))) {
|
2011-06-04 16:06:11 +08:00
|
|
|
if (likely(mem_init_done))
|
|
|
|
vfree(area->addr);
|
|
|
|
else
|
|
|
|
fixmaps_used -= (size >> PAGE_SHIFT);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (void __iomem *)(offset + (char *)v);
|
|
|
|
}
|
2019-08-17 15:32:32 +08:00
|
|
|
EXPORT_SYMBOL(ioremap);
|
2011-06-04 16:06:11 +08:00
|
|
|
|
|
|
|
void iounmap(void *addr)
|
|
|
|
{
|
|
|
|
/* If the page is from the fixmap pool then we just clear out
|
|
|
|
* the fixmap mapping.
|
|
|
|
*/
|
|
|
|
if (unlikely((unsigned long)addr > FIXADDR_START)) {
|
|
|
|
/* This is a bit broken... we don't really know
|
|
|
|
* how big the area is so it's difficult to know
|
|
|
|
* how many fixed pages to invalidate...
|
|
|
|
* just flush tlb and hope for the best...
|
|
|
|
* consider this a FIXME
|
|
|
|
*
|
|
|
|
* Really we should be clearing out one or more page
|
|
|
|
* table entries for these virtual addresses so that
|
|
|
|
* future references cause a page fault... for now, we
|
|
|
|
* rely on two things:
|
|
|
|
* i) this code never gets called on known boards
|
|
|
|
* ii) invalid accesses to the freed areas aren't made
|
|
|
|
*/
|
|
|
|
flush_tlb_all();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vfree((void *)(PAGE_MASK & (unsigned long)addr));
|
|
|
|
}
|
2017-02-05 14:32:26 +08:00
|
|
|
EXPORT_SYMBOL(iounmap);
|
2011-06-04 16:06:11 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* OK, this one's a bit tricky... ioremap can get called before memory is
|
|
|
|
* initialized (early serial console does this) and will want to alloc a page
|
|
|
|
* for its mapping. No userspace pages will ever get allocated before memory
|
|
|
|
* is initialized so this applies only to kernel pages. In the event that
|
|
|
|
* this is called before memory is initialized we allocate the page using
|
|
|
|
* the memblock infrastructure.
|
|
|
|
*/
|
|
|
|
|
mm: treewide: remove unused address argument from pte_alloc functions
Patch series "Add support for fast mremap".
This series speeds up the mremap(2) syscall by copying page tables at
the PMD level even for non-THP systems. There is concern that the extra
'address' argument that mremap passes to pte_alloc may do something
subtle architecture related in the future that may make the scheme not
work. Also we find that there is no point in passing the 'address' to
pte_alloc since its unused. This patch therefore removes this argument
tree-wide resulting in a nice negative diff as well. Also ensuring
along the way that the enabled architectures do not do anything funky
with the 'address' argument that goes unnoticed by the optimization.
Build and boot tested on x86-64. Build tested on arm64. The config
enablement patch for arm64 will be posted in the future after more
testing.
The changes were obtained by applying the following Coccinelle script.
(thanks Julia for answering all Coccinelle questions!).
Following fix ups were done manually:
* Removal of address argument from pte_fragment_alloc
* Removal of pte_alloc_one_fast definitions from m68k and microblaze.
// Options: --include-headers --no-includes
// Note: I split the 'identifier fn' line, so if you are manually
// running it, please unsplit it so it runs for you.
virtual patch
@pte_alloc_func_def depends on patch exists@
identifier E2;
identifier fn =~
"^(__pte_alloc|pte_alloc_one|pte_alloc|__pte_alloc_kernel|pte_alloc_one_kernel)$";
type T2;
@@
fn(...
- , T2 E2
)
{ ... }
@pte_alloc_func_proto_noarg depends on patch exists@
type T1, T2, T3, T4;
identifier fn =~ "^(__pte_alloc|pte_alloc_one|pte_alloc|__pte_alloc_kernel|pte_alloc_one_kernel)$";
@@
(
- T3 fn(T1, T2);
+ T3 fn(T1);
|
- T3 fn(T1, T2, T4);
+ T3 fn(T1, T2);
)
@pte_alloc_func_proto depends on patch exists@
identifier E1, E2, E4;
type T1, T2, T3, T4;
identifier fn =~
"^(__pte_alloc|pte_alloc_one|pte_alloc|__pte_alloc_kernel|pte_alloc_one_kernel)$";
@@
(
- T3 fn(T1 E1, T2 E2);
+ T3 fn(T1 E1);
|
- T3 fn(T1 E1, T2 E2, T4 E4);
+ T3 fn(T1 E1, T2 E2);
)
@pte_alloc_func_call depends on patch exists@
expression E2;
identifier fn =~
"^(__pte_alloc|pte_alloc_one|pte_alloc|__pte_alloc_kernel|pte_alloc_one_kernel)$";
@@
fn(...
-, E2
)
@pte_alloc_macro depends on patch exists@
identifier fn =~
"^(__pte_alloc|pte_alloc_one|pte_alloc|__pte_alloc_kernel|pte_alloc_one_kernel)$";
identifier a, b, c;
expression e;
position p;
@@
(
- #define fn(a, b, c) e
+ #define fn(a, b) e
|
- #define fn(a, b) e
+ #define fn(a) e
)
Link: http://lkml.kernel.org/r/20181108181201.88826-2-joelaf@google.com
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Suggested-by: Kirill A. Shutemov <kirill@shutemov.name>
Acked-by: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: William Kucharski <william.kucharski@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-04 07:28:34 +08:00
|
|
|
pte_t __ref *pte_alloc_one_kernel(struct mm_struct *mm)
|
2011-06-04 16:06:11 +08:00
|
|
|
{
|
|
|
|
pte_t *pte;
|
|
|
|
|
2019-03-12 14:30:31 +08:00
|
|
|
if (likely(mem_init_done)) {
|
2019-03-08 08:31:01 +08:00
|
|
|
pte = (pte_t *)get_zeroed_page(GFP_KERNEL);
|
2019-03-12 14:30:31 +08:00
|
|
|
} else {
|
2019-03-08 08:31:01 +08:00
|
|
|
pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
|
2019-03-12 14:30:31 +08:00
|
|
|
if (!pte)
|
|
|
|
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
|
|
|
|
__func__, PAGE_SIZE, PAGE_SIZE);
|
|
|
|
}
|
2011-06-04 16:06:11 +08:00
|
|
|
|
|
|
|
return pte;
|
|
|
|
}
|