]>
git.ipfire.org Git - thirdparty/linux.git/blob - mm/ioremap.c
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 phys_addr
, size_t size
,
17 unsigned long offset
, vaddr
;
18 phys_addr_t last_addr
;
19 struct vm_struct
*area
;
21 /* Disallow wrap-around or zero size */
22 last_addr
= phys_addr
+ size
- 1;
23 if (!size
|| last_addr
< phys_addr
)
26 /* Page-align mappings */
27 offset
= phys_addr
& (~PAGE_MASK
);
29 size
= PAGE_ALIGN(size
+ offset
);
31 if (!ioremap_allowed(phys_addr
, size
, prot
))
34 area
= get_vm_area_caller(size
, VM_IOREMAP
,
35 __builtin_return_address(0));
38 vaddr
= (unsigned long)area
->addr
;
39 area
->phys_addr
= phys_addr
;
41 if (ioremap_page_range(vaddr
, vaddr
+ size
, phys_addr
,
47 return (void __iomem
*)(vaddr
+ offset
);
49 EXPORT_SYMBOL(ioremap_prot
);
51 void iounmap(volatile void __iomem
*addr
)
53 void *vaddr
= (void *)((unsigned long)addr
& PAGE_MASK
);
55 if (!iounmap_allowed(vaddr
))
58 if (is_vmalloc_addr(vaddr
))
61 EXPORT_SYMBOL(iounmap
);