File: ioremap.c

package info (click to toggle)
linux 5.10.46-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,191,996 kB
  • sloc: ansic: 19,502,768; asm: 263,759; sh: 73,960; makefile: 44,724; perl: 34,644; python: 32,387; cpp: 6,070; yacc: 4,755; lex: 2,742; awk: 1,214; ruby: 25; sed: 5
file content (65 lines) | stat: -rw-r--r-- 1,436 bytes parent folder | download | duplicates (11)
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 <linux/pgtable.h>
#include <asm/cacheflush.h>
#include <asm/io.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);