1 // SPDX-License-Identifier: GPL-2.0
3 * arch/cris/mm/ioremap.c
5 * Re-map IO memory to kernel address space so that we can access it.
6 * Needed for memory-mapped I/O devices mapped outside our normal DRAM
7 * window (that is, all memory-mapped I/O devices).
9 * (C) Copyright 1995 1996 Linus Torvalds
10 * CRIS-port by Axis Communications AB
13 #include <linux/vmalloc.h>
15 #include <asm/pgalloc.h>
16 #include <arch/memmap.h>
19 * Generic mapping function (not visible outside):
23 * Remap an arbitrary physical address space into the kernel virtual
24 * address space. Needed when the kernel wants to access high addresses
27 * NOTE! We need to allow non-page-aligned mappings too: we will obviously
28 * have to convert them into an offset in a page-aligned mapping, but the
29 * caller shouldn't need to know that small detail.
31 void __iomem
* __ioremap_prot(unsigned long phys_addr
, unsigned long size
, pgprot_t prot
)
34 struct vm_struct
* area
;
35 unsigned long offset
, last_addr
;
37 /* Don't allow wraparound or zero size */
38 last_addr
= phys_addr
+ size
- 1;
39 if (!size
|| last_addr
< phys_addr
)
43 * Mappings have to be page-aligned
45 offset
= phys_addr
& ~PAGE_MASK
;
46 phys_addr
&= PAGE_MASK
;
47 size
= PAGE_ALIGN(last_addr
+1) - phys_addr
;
52 area
= get_vm_area(size
, VM_IOREMAP
);
55 addr
= (void __iomem
*)area
->addr
;
56 if (ioremap_page_range((unsigned long)addr
, (unsigned long)addr
+ size
,
58 vfree((void __force
*)addr
);
61 return (void __iomem
*) (offset
+ (char __iomem
*)addr
);
64 void __iomem
* __ioremap(unsigned long phys_addr
, unsigned long size
, unsigned long flags
)
66 return __ioremap_prot(phys_addr
, size
,
67 __pgprot(_PAGE_PRESENT
| __READABLE
|
68 __WRITEABLE
| _PAGE_GLOBAL
|
69 _PAGE_KERNEL
| flags
));
73 * ioremap_nocache - map bus memory into CPU space
74 * @offset: bus address of the memory
75 * @size: size of the resource to map
77 * Must be freed with iounmap.
80 void __iomem
*ioremap_nocache(unsigned long phys_addr
, unsigned long size
)
82 return __ioremap(phys_addr
| MEM_NON_CACHEABLE
, size
, 0);
84 EXPORT_SYMBOL(ioremap_nocache
);
86 void iounmap(volatile void __iomem
*addr
)
88 if (addr
> high_memory
)
89 return vfree((void *) (PAGE_MASK
& (unsigned long) addr
));