diff options
author | Matt Fleming <matt@console-pimps.org> | 2009-11-05 15:49:05 -0500 |
---|---|---|
committer | Matt Fleming <matt@console-pimps.org> | 2010-01-16 09:31:51 -0500 |
commit | 597fe76ec36e782aa45b8dac5e12e4dbb0588967 (patch) | |
tree | dd58806e4e2953451d23dafd388ccdb7877f956a /arch/sh/mm | |
parent | 6f82b6ebb1dcc0c3c23820a70a5d79a60c4f5e84 (diff) |
sh: Use ioremap_fixed() to implement SH-5 ioremap()
Use the fixmap-based memory mapping implementation for SH-5's ioremap()
functions and delete the old static allocator that was borrowed from
sparc.
Signed-off-by: Matt Fleming <matt@console-pimps.org>
Diffstat (limited to 'arch/sh/mm')
-rw-r--r-- | arch/sh/mm/ioremap_64.c | 287 |
1 files changed, 4 insertions, 283 deletions
diff --git a/arch/sh/mm/ioremap_64.c b/arch/sh/mm/ioremap_64.c index ef434657d428..fb0aa457c71e 100644 --- a/arch/sh/mm/ioremap_64.c +++ b/arch/sh/mm/ioremap_64.c | |||
@@ -28,299 +28,20 @@ | |||
28 | #include <asm/tlbflush.h> | 28 | #include <asm/tlbflush.h> |
29 | #include <asm/mmu.h> | 29 | #include <asm/mmu.h> |
30 | 30 | ||
31 | static struct resource shmedia_iomap = { | 31 | void __iomem *__ioremap_caller(unsigned long offset, unsigned long size, |
32 | .name = "shmedia_iomap", | 32 | unsigned long flags, void *caller) |
33 | .start = IOBASE_VADDR + PAGE_SIZE, | ||
34 | .end = IOBASE_END - 1, | ||
35 | }; | ||
36 | |||
37 | static void shmedia_mapioaddr(unsigned long pa, unsigned long va, | ||
38 | unsigned long flags); | ||
39 | static void shmedia_unmapioaddr(unsigned long vaddr); | ||
40 | static void __iomem *shmedia_ioremap(struct resource *res, u32 pa, | ||
41 | int sz, unsigned long flags); | ||
42 | |||
43 | /* | ||
44 | * We have the same problem as the SPARC, so lets have the same comment: | ||
45 | * Our mini-allocator... | ||
46 | * Boy this is gross! We need it because we must map I/O for | ||
47 | * timers and interrupt controller before the kmalloc is available. | ||
48 | */ | ||
49 | |||
50 | #define XNMLN 15 | ||
51 | #define XNRES 10 | ||
52 | |||
53 | struct xresource { | ||
54 | struct resource xres; /* Must be first */ | ||
55 | int xflag; /* 1 == used */ | ||
56 | char xname[XNMLN+1]; | ||
57 | }; | ||
58 | |||
59 | static struct xresource xresv[XNRES]; | ||
60 | |||
61 | static struct xresource *xres_alloc(void) | ||
62 | { | ||
63 | struct xresource *xrp; | ||
64 | int n; | ||
65 | |||
66 | xrp = xresv; | ||
67 | for (n = 0; n < XNRES; n++) { | ||
68 | if (xrp->xflag == 0) { | ||
69 | xrp->xflag = 1; | ||
70 | return xrp; | ||
71 | } | ||
72 | xrp++; | ||
73 | } | ||
74 | return NULL; | ||
75 | } | ||
76 | |||
77 | static void xres_free(struct xresource *xrp) | ||
78 | { | ||
79 | xrp->xflag = 0; | ||
80 | } | ||
81 | |||
82 | static struct resource *shmedia_find_resource(struct resource *root, | ||
83 | unsigned long vaddr) | ||
84 | { | ||
85 | struct resource *res; | ||
86 | |||
87 | for (res = root->child; res; res = res->sibling) | ||
88 | if (res->start <= vaddr && res->end >= vaddr) | ||
89 | return res; | ||
90 | |||
91 | return NULL; | ||
92 | } | ||
93 | |||
94 | static void __iomem *shmedia_alloc_io(unsigned long phys, unsigned long size, | ||
95 | const char *name, unsigned long flags) | ||
96 | { | ||
97 | struct xresource *xres; | ||
98 | struct resource *res; | ||
99 | char *tack; | ||
100 | int tlen; | ||
101 | |||
102 | if (name == NULL) | ||
103 | name = "???"; | ||
104 | |||
105 | xres = xres_alloc(); | ||
106 | if (xres != 0) { | ||
107 | tack = xres->xname; | ||
108 | res = &xres->xres; | ||
109 | } else { | ||
110 | printk_once(KERN_NOTICE "%s: done with statics, " | ||
111 | "switching to kmalloc\n", __func__); | ||
112 | tlen = strlen(name); | ||
113 | tack = kmalloc(sizeof(struct resource) + tlen + 1, GFP_KERNEL); | ||
114 | if (!tack) | ||
115 | return NULL; | ||
116 | memset(tack, 0, sizeof(struct resource)); | ||
117 | res = (struct resource *) tack; | ||
118 | tack += sizeof(struct resource); | ||
119 | } | ||
120 | |||
121 | strncpy(tack, name, XNMLN); | ||
122 | tack[XNMLN] = 0; | ||
123 | res->name = tack; | ||
124 | |||
125 | return shmedia_ioremap(res, phys, size, flags); | ||
126 | } | ||
127 | |||
128 | static void __iomem *shmedia_ioremap(struct resource *res, u32 pa, int sz, | ||
129 | unsigned long flags) | ||
130 | { | ||
131 | unsigned long offset = ((unsigned long) pa) & (~PAGE_MASK); | ||
132 | unsigned long round_sz = (offset + sz + PAGE_SIZE-1) & PAGE_MASK; | ||
133 | unsigned long va; | ||
134 | unsigned int psz; | ||
135 | |||
136 | if (allocate_resource(&shmedia_iomap, res, round_sz, | ||
137 | shmedia_iomap.start, shmedia_iomap.end, | ||
138 | PAGE_SIZE, NULL, NULL) != 0) { | ||
139 | panic("alloc_io_res(%s): cannot occupy\n", | ||
140 | (res->name != NULL) ? res->name : "???"); | ||
141 | } | ||
142 | |||
143 | va = res->start; | ||
144 | pa &= PAGE_MASK; | ||
145 | |||
146 | psz = (res->end - res->start + (PAGE_SIZE - 1)) / PAGE_SIZE; | ||
147 | |||
148 | for (psz = res->end - res->start + 1; psz != 0; psz -= PAGE_SIZE) { | ||
149 | shmedia_mapioaddr(pa, va, flags); | ||
150 | va += PAGE_SIZE; | ||
151 | pa += PAGE_SIZE; | ||
152 | } | ||
153 | |||
154 | return (void __iomem *)(unsigned long)(res->start + offset); | ||
155 | } | ||
156 | |||
157 | static void shmedia_free_io(struct resource *res) | ||
158 | { | ||
159 | unsigned long len = res->end - res->start + 1; | ||
160 | |||
161 | BUG_ON((len & (PAGE_SIZE - 1)) != 0); | ||
162 | |||
163 | while (len) { | ||
164 | len -= PAGE_SIZE; | ||
165 | shmedia_unmapioaddr(res->start + len); | ||
166 | } | ||
167 | |||
168 | release_resource(res); | ||
169 | } | ||
170 | |||
171 | static __init_refok void *sh64_get_page(void) | ||
172 | { | ||
173 | void *page; | ||
174 | |||
175 | if (slab_is_available()) | ||
176 | page = (void *)get_zeroed_page(GFP_KERNEL); | ||
177 | else | ||
178 | page = alloc_bootmem_pages(PAGE_SIZE); | ||
179 | |||
180 | if (!page || ((unsigned long)page & ~PAGE_MASK)) | ||
181 | panic("sh64_get_page: Out of memory already?\n"); | ||
182 | |||
183 | return page; | ||
184 | } | ||
185 | |||
186 | static void shmedia_mapioaddr(unsigned long pa, unsigned long va, | ||
187 | unsigned long flags) | ||
188 | { | 33 | { |
189 | pgd_t *pgdp; | ||
190 | pud_t *pudp; | ||
191 | pmd_t *pmdp; | ||
192 | pte_t *ptep, pte; | ||
193 | pgprot_t prot; | 34 | pgprot_t prot; |
194 | 35 | ||
195 | pr_debug("shmedia_mapiopage pa %08lx va %08lx\n", pa, va); | ||
196 | |||
197 | if (!flags) | ||
198 | flags = 1; /* 1 = CB0-1 device */ | ||
199 | |||
200 | pgdp = pgd_offset_k(va); | ||
201 | if (pgd_none(*pgdp) || !pgd_present(*pgdp)) { | ||
202 | pudp = (pud_t *)sh64_get_page(); | ||
203 | set_pgd(pgdp, __pgd((unsigned long)pudp | _KERNPG_TABLE)); | ||
204 | } | ||
205 | |||
206 | pudp = pud_offset(pgdp, va); | ||
207 | if (pud_none(*pudp) || !pud_present(*pudp)) { | ||
208 | pmdp = (pmd_t *)sh64_get_page(); | ||
209 | set_pud(pudp, __pud((unsigned long)pmdp | _KERNPG_TABLE)); | ||
210 | } | ||
211 | |||
212 | pmdp = pmd_offset(pudp, va); | ||
213 | if (pmd_none(*pmdp) || !pmd_present(*pmdp)) { | ||
214 | ptep = (pte_t *)sh64_get_page(); | ||
215 | set_pmd(pmdp, __pmd((unsigned long)ptep + _PAGE_TABLE)); | ||
216 | } | ||
217 | |||
218 | prot = __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | | 36 | prot = __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | |
219 | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_SHARED | flags); | 37 | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_SHARED | flags); |
220 | 38 | ||
221 | pte = pfn_pte(pa >> PAGE_SHIFT, prot); | 39 | return ioremap_fixed(offset, size, prot); |
222 | ptep = pte_offset_kernel(pmdp, va); | ||
223 | |||
224 | if (!pte_none(*ptep) && | ||
225 | pte_val(*ptep) != pte_val(pte)) | ||
226 | pte_ERROR(*ptep); | ||
227 | |||
228 | set_pte(ptep, pte); | ||
229 | |||
230 | flush_tlb_kernel_range(va, PAGE_SIZE); | ||
231 | } | ||
232 | |||
233 | static void shmedia_unmapioaddr(unsigned long vaddr) | ||
234 | { | ||
235 | pgd_t *pgdp; | ||
236 | pud_t *pudp; | ||
237 | pmd_t *pmdp; | ||
238 | pte_t *ptep; | ||
239 | |||
240 | pgdp = pgd_offset_k(vaddr); | ||
241 | if (pgd_none(*pgdp) || pgd_bad(*pgdp)) | ||
242 | return; | ||
243 | |||
244 | pudp = pud_offset(pgdp, vaddr); | ||
245 | if (pud_none(*pudp) || pud_bad(*pudp)) | ||
246 | return; | ||
247 | |||
248 | pmdp = pmd_offset(pudp, vaddr); | ||
249 | if (pmd_none(*pmdp) || pmd_bad(*pmdp)) | ||
250 | return; | ||
251 | |||
252 | ptep = pte_offset_kernel(pmdp, vaddr); | ||
253 | |||
254 | if (pte_none(*ptep) || !pte_present(*ptep)) | ||
255 | return; | ||
256 | |||
257 | clear_page((void *)ptep); | ||
258 | pte_clear(&init_mm, vaddr, ptep); | ||
259 | } | ||
260 | |||
261 | void __iomem *__ioremap_caller(unsigned long offset, unsigned long size, | ||
262 | unsigned long flags, void *caller) | ||
263 | { | ||
264 | char name[14]; | ||
265 | |||
266 | sprintf(name, "phys_%08x", (u32)offset); | ||
267 | return shmedia_alloc_io(offset, size, name, flags); | ||
268 | } | 40 | } |
269 | EXPORT_SYMBOL(__ioremap_caller); | 41 | EXPORT_SYMBOL(__ioremap_caller); |
270 | 42 | ||
271 | void __iounmap(void __iomem *virtual) | 43 | void __iounmap(void __iomem *virtual) |
272 | { | 44 | { |
273 | unsigned long vaddr = (unsigned long)virtual & PAGE_MASK; | 45 | iounmap_fixed(virtual); |
274 | struct resource *res; | ||
275 | unsigned int psz; | ||
276 | |||
277 | res = shmedia_find_resource(&shmedia_iomap, vaddr); | ||
278 | if (!res) { | ||
279 | printk(KERN_ERR "%s: Failed to free 0x%08lx\n", | ||
280 | __func__, vaddr); | ||
281 | return; | ||
282 | } | ||
283 | |||
284 | psz = (res->end - res->start + (PAGE_SIZE - 1)) / PAGE_SIZE; | ||
285 | |||
286 | shmedia_free_io(res); | ||
287 | |||
288 | if ((char *)res >= (char *)xresv && | ||
289 | (char *)res < (char *)&xresv[XNRES]) { | ||
290 | xres_free((struct xresource *)res); | ||
291 | } else { | ||
292 | kfree(res); | ||
293 | } | ||
294 | } | 46 | } |
295 | EXPORT_SYMBOL(__iounmap); | 47 | EXPORT_SYMBOL(__iounmap); |
296 | |||
297 | static int | ||
298 | ioremap_proc_info(char *buf, char **start, off_t fpos, int length, int *eof, | ||
299 | void *data) | ||
300 | { | ||
301 | char *p = buf, *e = buf + length; | ||
302 | struct resource *r; | ||
303 | const char *nm; | ||
304 | |||
305 | for (r = ((struct resource *)data)->child; r != NULL; r = r->sibling) { | ||
306 | if (p + 32 >= e) /* Better than nothing */ | ||
307 | break; | ||
308 | nm = r->name; | ||
309 | if (nm == NULL) | ||
310 | nm = "???"; | ||
311 | |||
312 | p += sprintf(p, "%08lx-%08lx: %s\n", | ||
313 | (unsigned long)r->start, | ||
314 | (unsigned long)r->end, nm); | ||
315 | } | ||
316 | |||
317 | return p-buf; | ||
318 | } | ||
319 | |||
320 | static int __init register_proc_onchip(void) | ||
321 | { | ||
322 | create_proc_read_entry("io_map", 0, 0, ioremap_proc_info, | ||
323 | &shmedia_iomap); | ||
324 | return 0; | ||
325 | } | ||
326 | late_initcall(register_proc_onchip); | ||