Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / arch / parisc / mm / ioremap.c
blob345ff0b664993584dd257f8b37039074c183fcbf
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * arch/parisc/mm/ioremap.c
5 * (C) Copyright 1995 1996 Linus Torvalds
6 * (C) Copyright 2001-2019 Helge Deller <deller@gmx.de>
7 * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org>
8 */
10 #include <linux/vmalloc.h>
11 #include <linux/errno.h>
12 #include <linux/module.h>
13 #include <linux/io.h>
14 #include <linux/mm.h>
17 * Generic mapping function (not visible outside):
21 * Remap an arbitrary physical address space into the kernel virtual
22 * address space.
24 * NOTE! We need to allow non-page-aligned mappings too: we will obviously
25 * have to convert them into an offset in a page-aligned mapping, but the
26 * caller shouldn't need to know that small detail.
28 void __iomem *ioremap(unsigned long phys_addr, unsigned long size)
30 void __iomem *addr;
31 struct vm_struct *area;
32 unsigned long offset, last_addr;
33 pgprot_t pgprot;
35 #ifdef CONFIG_EISA
36 unsigned long end = phys_addr + size - 1;
37 /* Support EISA addresses */
38 if ((phys_addr >= 0x00080000 && end < 0x000fffff) ||
39 (phys_addr >= 0x00500000 && end < 0x03bfffff))
40 phys_addr |= F_EXTEND(0xfc000000);
41 #endif
43 /* Don't allow wraparound or zero size */
44 last_addr = phys_addr + size - 1;
45 if (!size || last_addr < phys_addr)
46 return NULL;
49 * Don't allow anybody to remap normal RAM that we're using..
51 if (phys_addr < virt_to_phys(high_memory)) {
52 char *t_addr, *t_end;
53 struct page *page;
55 t_addr = __va(phys_addr);
56 t_end = t_addr + (size - 1);
58 for (page = virt_to_page(t_addr);
59 page <= virt_to_page(t_end); page++) {
60 if(!PageReserved(page))
61 return NULL;
65 pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY |
66 _PAGE_ACCESSED | _PAGE_NO_CACHE);
69 * Mappings have to be page-aligned
71 offset = phys_addr & ~PAGE_MASK;
72 phys_addr &= PAGE_MASK;
73 size = PAGE_ALIGN(last_addr + 1) - phys_addr;
76 * Ok, go for it..
78 area = get_vm_area(size, VM_IOREMAP);
79 if (!area)
80 return NULL;
82 addr = (void __iomem *) area->addr;
83 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
84 phys_addr, pgprot)) {
85 vunmap(addr);
86 return NULL;
89 return (void __iomem *) (offset + (char __iomem *)addr);
91 EXPORT_SYMBOL(ioremap);
93 void iounmap(const volatile void __iomem *io_addr)
95 unsigned long addr = (unsigned long)io_addr & PAGE_MASK;
97 if (is_vmalloc_addr((void *)addr))
98 vunmap((void *)addr);
100 EXPORT_SYMBOL(iounmap);