2 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/vmalloc.h>
10 #include <linux/init.h>
11 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <linux/cache.h>
17 void __iomem *ioremap(phys_addr_t paddr, unsigned long size)
21 /* Don't allow wraparound or zero size */
22 end = paddr + size - 1;
23 if (!size || (end < paddr))
27 * If the region is h/w uncached, MMU mapping can be elided as optim
28 * The cast to u32 is fine as this region can only be inside 4GB
30 if (paddr >= ARC_UNCACHED_ADDR_SPACE)
31 return (void __iomem *)(u32)paddr;
33 return ioremap_prot(paddr, size, PAGE_KERNEL_NO_CACHE);
35 EXPORT_SYMBOL(ioremap);
38 * ioremap with access flags
39 * Cache semantics wise it is same as ioremap - "forced" uncached.
40 * However unline vanilla ioremap which bypasses ARC MMU for addresses in
41 * ARC hardware uncached region, this one still goes thru the MMU as caller
42 * might need finer access control (R/W/X)
44 void __iomem *ioremap_prot(phys_addr_t paddr, unsigned long size,
48 struct vm_struct *area;
50 pgprot_t prot = __pgprot(flags);
52 /* Don't allow wraparound, zero size */
53 end = paddr + size - 1;
54 if ((!size) || (end < paddr))
57 /* An early platform driver might end up here */
58 if (!slab_is_available())
62 prot = pgprot_noncached(prot);
64 /* Mappings have to be page-aligned */
65 off = paddr & ~PAGE_MASK;
67 size = PAGE_ALIGN(end + 1) - paddr;
72 area = get_vm_area(size, VM_IOREMAP);
75 area->phys_addr = paddr;
76 vaddr = (unsigned long)area->addr;
77 if (ioremap_page_range(vaddr, vaddr + size, paddr, prot)) {
78 vunmap((void __force *)vaddr);
81 return (void __iomem *)(off + (char __iomem *)vaddr);
83 EXPORT_SYMBOL(ioremap_prot);
86 void iounmap(const void __iomem *addr)
88 if (addr >= (void __force __iomem *)ARC_UNCACHED_ADDR_SPACE)
91 vfree((void *)(PAGE_MASK & (unsigned long __force)addr));
93 EXPORT_SYMBOL(iounmap);