1
2
3
4
5
6
7
8
9
10
11
12#include <linux/vmalloc.h>
13#include <linux/io.h>
14#include <asm/pgalloc.h>
15#include <arch/memmap.h>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30void __iomem * __ioremap_prot(unsigned long phys_addr, unsigned long size, pgprot_t prot)
31{
32 void __iomem * addr;
33 struct vm_struct * area;
34 unsigned long offset, last_addr;
35
36
37 last_addr = phys_addr + size - 1;
38 if (!size || last_addr < phys_addr)
39 return NULL;
40
41
42
43
44 offset = phys_addr & ~PAGE_MASK;
45 phys_addr &= PAGE_MASK;
46 size = PAGE_ALIGN(last_addr+1) - phys_addr;
47
48
49
50
51 area = get_vm_area(size, VM_IOREMAP);
52 if (!area)
53 return NULL;
54 addr = (void __iomem *)area->addr;
55 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
56 phys_addr, prot)) {
57 vfree((void __force *)addr);
58 return NULL;
59 }
60 return (void __iomem *) (offset + (char __iomem *)addr);
61}
62
63void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flags)
64{
65 return __ioremap_prot(phys_addr, size,
66 __pgprot(_PAGE_PRESENT | __READABLE |
67 __WRITEABLE | _PAGE_GLOBAL |
68 _PAGE_KERNEL | flags));
69}
70
71
72
73
74
75
76
77
78
79void __iomem *ioremap_nocache(unsigned long phys_addr, unsigned long size)
80{
81 return __ioremap(phys_addr | MEM_NON_CACHEABLE, size, 0);
82}
83EXPORT_SYMBOL(ioremap_nocache);
84
85void iounmap(volatile void __iomem *addr)
86{
87 if (addr > high_memory)
88 return vfree((void *) (PAGE_MASK & (unsigned long) addr));
89}
90