summaryrefslogtreecommitdiff
path: root/arch/xtensa/mm/ioremap.c
blob: bfefe16da26d1c1d0a14cba67d9851eed78089be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: GPL-2.0-only
/*
 * ioremap implementation.
 *
 * Copyright (C) 2015 Cadence Design Systems Inc.
 */

#include <linux/io.h>
#include <linux/vmalloc.h>
#include <asm/cacheflush.h>
#include <asm/io.h>
#include <linux/pgtable.h>

static void __iomem *xtensa_ioremap(unsigned long paddr, unsigned long size,
				    pgprot_t prot)
{
	unsigned long offset = paddr & ~PAGE_MASK;
	unsigned long pfn = __phys_to_pfn(paddr);
	struct vm_struct *area;
	unsigned long vaddr;
	int err;

	paddr &= PAGE_MASK;

	WARN_ON(pfn_valid(pfn));

	size = PAGE_ALIGN(offset + size);

	area = get_vm_area(size, VM_IOREMAP);
	if (!area)
		return NULL;

	vaddr = (unsigned long)area->addr;
	area->phys_addr = paddr;

	err = ioremap_page_range(vaddr, vaddr + size, paddr, prot);

	if (err) {
		vunmap((void *)vaddr);
		return NULL;
	}

	flush_cache_vmap(vaddr, vaddr + size);
	return (void __iomem *)(offset + vaddr);
}

void __iomem *xtensa_ioremap_nocache(unsigned long addr, unsigned long size)
{
	return xtensa_ioremap(addr, size, pgprot_noncached(PAGE_KERNEL));
}
EXPORT_SYMBOL(xtensa_ioremap_nocache);

void __iomem *xtensa_ioremap_cache(unsigned long addr, unsigned long size)
{
	return xtensa_ioremap(addr, size, PAGE_KERNEL);
}
EXPORT_SYMBOL(xtensa_ioremap_cache);

void xtensa_iounmap(volatile void __iomem *io_addr)
{
	void *addr = (void *)(PAGE_MASK & (unsigned long)io_addr);

	vunmap(addr);
}
EXPORT_SYMBOL(xtensa_iounmap);