treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / hexagon / mm / ioremap.c
blob255c5b1ee1a711ab6369e526bdcdc6fcf445e632
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * I/O remap functions for Hexagon
5 * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
6 */
8 #include <linux/io.h>
9 #include <linux/vmalloc.h>
10 #include <linux/mm.h>
12 void __iomem *ioremap(unsigned long phys_addr, unsigned long size)
14 unsigned long last_addr, addr;
15 unsigned long offset = phys_addr & ~PAGE_MASK;
16 struct vm_struct *area;
18 pgprot_t prot = __pgprot(_PAGE_PRESENT|_PAGE_READ|_PAGE_WRITE
19 |(__HEXAGON_C_DEV << 6));
21 last_addr = phys_addr + size - 1;
23 /* Wrapping not allowed */
24 if (!size || (last_addr < phys_addr))
25 return NULL;
27 /* Rounds up to next page size, including whole-page offset */
28 size = PAGE_ALIGN(offset + size);
30 area = get_vm_area(size, VM_IOREMAP);
31 addr = (unsigned long)area->addr;
33 if (ioremap_page_range(addr, addr+size, phys_addr, prot)) {
34 vunmap((void *)addr);
35 return NULL;
38 return (void __iomem *) (offset + addr);
41 void iounmap(const volatile void __iomem *addr)
43 vunmap((void *) ((unsigned long) addr & PAGE_MASK));