2 * ioremap implementation.
4 * Copyright (C) 2015 Cadence Design Systems Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #include <linux/vmalloc.h>
13 #include <asm/cacheflush.h>
15 #include <asm/pgtable.h>
17 static void __iomem *xtensa_ioremap(unsigned long paddr, unsigned long size,
20 unsigned long offset = paddr & ~PAGE_MASK;
21 unsigned long pfn = __phys_to_pfn(paddr);
22 struct vm_struct *area;
28 WARN_ON(pfn_valid(pfn));
30 size = PAGE_ALIGN(offset + size);
32 area = get_vm_area(size, VM_IOREMAP);
36 vaddr = (unsigned long)area->addr;
37 area->phys_addr = paddr;
39 err = ioremap_page_range(vaddr, vaddr + size, paddr, prot);
42 vunmap((void *)vaddr);
46 flush_cache_vmap(vaddr, vaddr + size);
47 return (void __iomem *)(offset + vaddr);
50 void __iomem *xtensa_ioremap_nocache(unsigned long addr, unsigned long size)
52 return xtensa_ioremap(addr, size, pgprot_noncached(PAGE_KERNEL));
54 EXPORT_SYMBOL(xtensa_ioremap_nocache);
56 void __iomem *xtensa_ioremap_cache(unsigned long addr, unsigned long size)
58 return xtensa_ioremap(addr, size, PAGE_KERNEL);
60 EXPORT_SYMBOL(xtensa_ioremap_cache);
62 void xtensa_iounmap(volatile void __iomem *io_addr)
64 void *addr = (void *)(PAGE_MASK & (unsigned long)io_addr);
68 EXPORT_SYMBOL(xtensa_iounmap);