blob: 255c5b1ee1a711ab6369e526bdcdc6fcf445e632 [file] [log] [blame]
Thomas Gleixner08dbd0f2019-05-29 07:12:41 -07001// SPDX-License-Identifier: GPL-2.0-only
Richard Kuob7f37852011-10-31 18:52:53 -05002/*
3 * I/O remap functions for Hexagon
4 *
Richard Kuoe1858b22012-09-19 16:22:02 -05005 * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
Richard Kuob7f37852011-10-31 18:52:53 -05006 */
7
8#include <linux/io.h>
9#include <linux/vmalloc.h>
Guenter Roeckcb84c2b2014-12-09 14:21:45 -080010#include <linux/mm.h>
Richard Kuob7f37852011-10-31 18:52:53 -050011
Christoph Hellwigac322922019-08-12 23:27:12 +020012void __iomem *ioremap(unsigned long phys_addr, unsigned long size)
Richard Kuob7f37852011-10-31 18:52:53 -050013{
14 unsigned long last_addr, addr;
15 unsigned long offset = phys_addr & ~PAGE_MASK;
16 struct vm_struct *area;
17
18 pgprot_t prot = __pgprot(_PAGE_PRESENT|_PAGE_READ|_PAGE_WRITE
19 |(__HEXAGON_C_DEV << 6));
20
21 last_addr = phys_addr + size - 1;
22
23 /* Wrapping not allowed */
24 if (!size || (last_addr < phys_addr))
25 return NULL;
26
27 /* Rounds up to next page size, including whole-page offset */
28 size = PAGE_ALIGN(offset + size);
29
30 area = get_vm_area(size, VM_IOREMAP);
31 addr = (unsigned long)area->addr;
32
33 if (ioremap_page_range(addr, addr+size, phys_addr, prot)) {
34 vunmap((void *)addr);
35 return NULL;
36 }
37
38 return (void __iomem *) (offset + addr);
39}
40
Christoph Hellwig94251722019-08-13 08:11:46 +020041void iounmap(const volatile void __iomem *addr)
Richard Kuob7f37852011-10-31 18:52:53 -050042{
43 vunmap((void *) ((unsigned long) addr & PAGE_MASK));
44}