This source file includes following definitions.
- ioremap
- iounmap
- pte_alloc_one_kernel
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <linux/vmalloc.h>
15 #include <linux/io.h>
16 #include <asm/pgalloc.h>
17 #include <asm/kmap_types.h>
18 #include <asm/fixmap.h>
19 #include <asm/bug.h>
20 #include <asm/pgtable.h>
21 #include <linux/sched.h>
22 #include <asm/tlbflush.h>
23
24 extern int mem_init_done;
25
26 static unsigned int fixmaps_used __initdata;
27
28
29
30
31
32
33
34
35
36
37 void __iomem *__ref ioremap(phys_addr_t addr, unsigned long size)
38 {
39 phys_addr_t p;
40 unsigned long v;
41 unsigned long offset, last_addr;
42 struct vm_struct *area = NULL;
43
44
45 last_addr = addr + size - 1;
46 if (!size || last_addr < addr)
47 return NULL;
48
49
50
51
52 offset = addr & ~PAGE_MASK;
53 p = addr & PAGE_MASK;
54 size = PAGE_ALIGN(last_addr + 1) - p;
55
56 if (likely(mem_init_done)) {
57 area = get_vm_area(size, VM_IOREMAP);
58 if (!area)
59 return NULL;
60 v = (unsigned long)area->addr;
61 } else {
62 if ((fixmaps_used + (size >> PAGE_SHIFT)) > FIX_N_IOREMAPS)
63 return NULL;
64 v = fix_to_virt(FIX_IOREMAP_BEGIN + fixmaps_used);
65 fixmaps_used += (size >> PAGE_SHIFT);
66 }
67
68 if (ioremap_page_range(v, v + size, p,
69 __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_CI))) {
70 if (likely(mem_init_done))
71 vfree(area->addr);
72 else
73 fixmaps_used -= (size >> PAGE_SHIFT);
74 return NULL;
75 }
76
77 return (void __iomem *)(offset + (char *)v);
78 }
79 EXPORT_SYMBOL(ioremap);
80
81 void iounmap(void *addr)
82 {
83
84
85
86 if (unlikely((unsigned long)addr > FIXADDR_START)) {
87
88
89
90
91
92
93
94
95
96
97
98
99
100 flush_tlb_all();
101 return;
102 }
103
104 return vfree((void *)(PAGE_MASK & (unsigned long)addr));
105 }
106 EXPORT_SYMBOL(iounmap);
107
108
109
110
111
112
113
114
115
116
117 pte_t __ref *pte_alloc_one_kernel(struct mm_struct *mm)
118 {
119 pte_t *pte;
120
121 if (likely(mem_init_done)) {
122 pte = (pte_t *)get_zeroed_page(GFP_KERNEL);
123 } else {
124 pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
125 if (!pte)
126 panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
127 __func__, PAGE_SIZE, PAGE_SIZE);
128 }
129
130 return pte;
131 }