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