1 // SPDX-License-Identifier: GPL-2.0
3 * Re-map IO memory to kernel address space so that we can access it.
4 * This is needed for high PCI addresses that aren't mapped in the
5 * 640k-1MB IO memory area on PC's
7 * (C) Copyright 1995 1996 Linus Torvalds
9 #include <linux/vmalloc.h>
12 #include <linux/export.h>
14 void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot)
16 unsigned long offset, vaddr;
17 phys_addr_t last_addr;
18 struct vm_struct *area;
20 /* Disallow wrap-around or zero size */
21 last_addr = addr + size - 1;
22 if (!size || last_addr < addr)
25 /* Page-align mappings */
26 offset = addr & (~PAGE_MASK);
28 size = PAGE_ALIGN(size + offset);
30 area = get_vm_area_caller(size, VM_IOREMAP,
31 __builtin_return_address(0));
34 vaddr = (unsigned long)area->addr;
36 if (ioremap_page_range(vaddr, vaddr + size, addr, __pgprot(prot))) {
41 return (void __iomem *)(vaddr + offset);
43 EXPORT_SYMBOL(ioremap_prot);
45 void iounmap(volatile void __iomem *addr)
47 vunmap((void *)((unsigned long)addr & PAGE_MASK));
49 EXPORT_SYMBOL(iounmap);