1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/export.h>
24#include <linux/mm.h>
25#include <linux/vmalloc.h>
26#include <linux/io.h>
27
28#include <asm/fixmap.h>
29#include <asm/tlbflush.h>
30#include <asm/pgalloc.h>
31
32static void __iomem *__ioremap_caller(phys_addr_t phys_addr, size_t size,
33 pgprot_t prot, void *caller)
34{
35 unsigned long last_addr;
36 unsigned long offset = phys_addr & ~PAGE_MASK;
37 int err;
38 unsigned long addr;
39 struct vm_struct *area;
40
41
42
43
44
45 phys_addr &= PAGE_MASK;
46 size = PAGE_ALIGN(size + offset);
47
48
49
50
51 last_addr = phys_addr + size - 1;
52 if (!size || last_addr < phys_addr || (last_addr & ~PHYS_MASK))
53 return NULL;
54
55
56
57
58 if (WARN_ON(pfn_valid(__phys_to_pfn(phys_addr))))
59 return NULL;
60
61 area = get_vm_area_caller(size, VM_IOREMAP, caller);
62 if (!area)
63 return NULL;
64 addr = (unsigned long)area->addr;
65 area->phys_addr = phys_addr;
66
67 err = ioremap_page_range(addr, addr + size, phys_addr, prot);
68 if (err) {
69 vunmap((void *)addr);
70 return NULL;
71 }
72
73 return (void __iomem *)(offset + addr);
74}
75
76void __iomem *__ioremap(phys_addr_t phys_addr, size_t size, pgprot_t prot)
77{
78 return __ioremap_caller(phys_addr, size, prot,
79 __builtin_return_address(0));
80}
81EXPORT_SYMBOL(__ioremap);
82
83void __iounmap(volatile void __iomem *io_addr)
84{
85 unsigned long addr = (unsigned long)io_addr & PAGE_MASK;
86
87
88
89
90
91 if (is_vmalloc_addr((void *)addr))
92 vunmap((void *)addr);
93}
94EXPORT_SYMBOL(__iounmap);
95
96void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size)
97{
98
99 if (pfn_valid(__phys_to_pfn(phys_addr)))
100 return (void __iomem *)__phys_to_virt(phys_addr);
101
102 return __ioremap_caller(phys_addr, size, __pgprot(PROT_NORMAL),
103 __builtin_return_address(0));
104}
105EXPORT_SYMBOL(ioremap_cache);
106
107
108
109
110void __init early_ioremap_init(void)
111{
112 early_ioremap_setup();
113}
114