aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ppc64/mm/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/ppc64/mm/init.c')
-rw-r--r--arch/ppc64/mm/init.c201
1 files changed, 103 insertions, 98 deletions
diff --git a/arch/ppc64/mm/init.c b/arch/ppc64/mm/init.c
index a7149b9fc35c..4b42aff74d73 100644
--- a/arch/ppc64/mm/init.c
+++ b/arch/ppc64/mm/init.c
@@ -64,6 +64,7 @@
64#include <asm/iommu.h> 64#include <asm/iommu.h>
65#include <asm/abs_addr.h> 65#include <asm/abs_addr.h>
66#include <asm/vdso.h> 66#include <asm/vdso.h>
67#include <asm/imalloc.h>
67 68
68int mem_init_done; 69int mem_init_done;
69unsigned long ioremap_bot = IMALLOC_BASE; 70unsigned long ioremap_bot = IMALLOC_BASE;
@@ -136,14 +137,78 @@ void iounmap(volatile void __iomem *addr)
136 137
137#else 138#else
138 139
140static void unmap_im_area_pte(pmd_t *pmd, unsigned long addr,
141 unsigned long end)
142{
143 pte_t *pte;
144
145 pte = pte_offset_kernel(pmd, addr);
146 do {
147 pte_t ptent = ptep_get_and_clear(&ioremap_mm, addr, pte);
148 WARN_ON(!pte_none(ptent) && !pte_present(ptent));
149 } while (pte++, addr += PAGE_SIZE, addr != end);
150}
151
152static inline void unmap_im_area_pmd(pud_t *pud, unsigned long addr,
153 unsigned long end)
154{
155 pmd_t *pmd;
156 unsigned long next;
157
158 pmd = pmd_offset(pud, addr);
159 do {
160 next = pmd_addr_end(addr, end);
161 if (pmd_none_or_clear_bad(pmd))
162 continue;
163 unmap_im_area_pte(pmd, addr, next);
164 } while (pmd++, addr = next, addr != end);
165}
166
167static inline void unmap_im_area_pud(pgd_t *pgd, unsigned long addr,
168 unsigned long end)
169{
170 pud_t *pud;
171 unsigned long next;
172
173 pud = pud_offset(pgd, addr);
174 do {
175 next = pud_addr_end(addr, end);
176 if (pud_none_or_clear_bad(pud))
177 continue;
178 unmap_im_area_pmd(pud, addr, next);
179 } while (pud++, addr = next, addr != end);
180}
181
182static void unmap_im_area(unsigned long addr, unsigned long end)
183{
184 struct mm_struct *mm = &ioremap_mm;
185 unsigned long next;
186 pgd_t *pgd;
187
188 spin_lock(&mm->page_table_lock);
189
190 pgd = pgd_offset_i(addr);
191 flush_cache_vunmap(addr, end);
192 do {
193 next = pgd_addr_end(addr, end);
194 if (pgd_none_or_clear_bad(pgd))
195 continue;
196 unmap_im_area_pud(pgd, addr, next);
197 } while (pgd++, addr = next, addr != end);
198 flush_tlb_kernel_range(start, end);
199
200 spin_unlock(&mm->page_table_lock);
201}
202
139/* 203/*
140 * map_io_page currently only called by __ioremap 204 * map_io_page currently only called by __ioremap
141 * map_io_page adds an entry to the ioremap page table 205 * map_io_page adds an entry to the ioremap page table
142 * and adds an entry to the HPT, possibly bolting it 206 * and adds an entry to the HPT, possibly bolting it
143 */ 207 */
144static void map_io_page(unsigned long ea, unsigned long pa, int flags) 208static int map_io_page(unsigned long ea, unsigned long pa, int flags)
145{ 209{
146 pgd_t *pgdp; 210 pgd_t *pgdp;
211 pud_t *pudp;
147 pmd_t *pmdp; 212 pmd_t *pmdp;
148 pte_t *ptep; 213 pte_t *ptep;
149 unsigned long vsid; 214 unsigned long vsid;
@@ -151,9 +216,15 @@ static void map_io_page(unsigned long ea, unsigned long pa, int flags)
151 if (mem_init_done) { 216 if (mem_init_done) {
152 spin_lock(&ioremap_mm.page_table_lock); 217 spin_lock(&ioremap_mm.page_table_lock);
153 pgdp = pgd_offset_i(ea); 218 pgdp = pgd_offset_i(ea);
154 pmdp = pmd_alloc(&ioremap_mm, pgdp, ea); 219 pudp = pud_alloc(&ioremap_mm, pgdp, ea);
220 if (!pudp)
221 return -ENOMEM;
222 pmdp = pmd_alloc(&ioremap_mm, pudp, ea);
223 if (!pmdp)
224 return -ENOMEM;
155 ptep = pte_alloc_kernel(&ioremap_mm, pmdp, ea); 225 ptep = pte_alloc_kernel(&ioremap_mm, pmdp, ea);
156 226 if (!ptep)
227 return -ENOMEM;
157 pa = abs_to_phys(pa); 228 pa = abs_to_phys(pa);
158 set_pte_at(&ioremap_mm, ea, ptep, pfn_pte(pa >> PAGE_SHIFT, 229 set_pte_at(&ioremap_mm, ea, ptep, pfn_pte(pa >> PAGE_SHIFT,
159 __pgprot(flags))); 230 __pgprot(flags)));
@@ -181,6 +252,7 @@ static void map_io_page(unsigned long ea, unsigned long pa, int flags)
181 panic("map_io_page: could not insert mapping"); 252 panic("map_io_page: could not insert mapping");
182 } 253 }
183 } 254 }
255 return 0;
184} 256}
185 257
186 258
@@ -194,9 +266,14 @@ static void __iomem * __ioremap_com(unsigned long addr, unsigned long pa,
194 flags |= pgprot_val(PAGE_KERNEL); 266 flags |= pgprot_val(PAGE_KERNEL);
195 267
196 for (i = 0; i < size; i += PAGE_SIZE) 268 for (i = 0; i < size; i += PAGE_SIZE)
197 map_io_page(ea+i, pa+i, flags); 269 if (map_io_page(ea+i, pa+i, flags))
270 goto failure;
198 271
199 return (void __iomem *) (ea + (addr & ~PAGE_MASK)); 272 return (void __iomem *) (ea + (addr & ~PAGE_MASK));
273 failure:
274 if (mem_init_done)
275 unmap_im_area(ea, ea + size);
276 return NULL;
200} 277}
201 278
202 279
@@ -206,10 +283,11 @@ ioremap(unsigned long addr, unsigned long size)
206 return __ioremap(addr, size, _PAGE_NO_CACHE | _PAGE_GUARDED); 283 return __ioremap(addr, size, _PAGE_NO_CACHE | _PAGE_GUARDED);
207} 284}
208 285
209void __iomem * 286void __iomem * __ioremap(unsigned long addr, unsigned long size,
210__ioremap(unsigned long addr, unsigned long size, unsigned long flags) 287 unsigned long flags)
211{ 288{
212 unsigned long pa, ea; 289 unsigned long pa, ea;
290 void __iomem *ret;
213 291
214 /* 292 /*
215 * Choose an address to map it to. 293 * Choose an address to map it to.
@@ -232,12 +310,16 @@ __ioremap(unsigned long addr, unsigned long size, unsigned long flags)
232 if (area == NULL) 310 if (area == NULL)
233 return NULL; 311 return NULL;
234 ea = (unsigned long)(area->addr); 312 ea = (unsigned long)(area->addr);
313 ret = __ioremap_com(addr, pa, ea, size, flags);
314 if (!ret)
315 im_free(area->addr);
235 } else { 316 } else {
236 ea = ioremap_bot; 317 ea = ioremap_bot;
237 ioremap_bot += size; 318 ret = __ioremap_com(addr, pa, ea, size, flags);
319 if (ret)
320 ioremap_bot += size;
238 } 321 }
239 322 return ret;
240 return __ioremap_com(addr, pa, ea, size, flags);
241} 323}
242 324
243#define IS_PAGE_ALIGNED(_val) ((_val) == ((_val) & PAGE_MASK)) 325#define IS_PAGE_ALIGNED(_val) ((_val) == ((_val) & PAGE_MASK))
@@ -246,6 +328,7 @@ int __ioremap_explicit(unsigned long pa, unsigned long ea,
246 unsigned long size, unsigned long flags) 328 unsigned long size, unsigned long flags)
247{ 329{
248 struct vm_struct *area; 330 struct vm_struct *area;
331 void __iomem *ret;
249 332
250 /* For now, require page-aligned values for pa, ea, and size */ 333 /* For now, require page-aligned values for pa, ea, and size */
251 if (!IS_PAGE_ALIGNED(pa) || !IS_PAGE_ALIGNED(ea) || 334 if (!IS_PAGE_ALIGNED(pa) || !IS_PAGE_ALIGNED(ea) ||
@@ -276,7 +359,12 @@ int __ioremap_explicit(unsigned long pa, unsigned long ea,
276 } 359 }
277 } 360 }
278 361
279 if (__ioremap_com(pa, pa, ea, size, flags) != (void *) ea) { 362 ret = __ioremap_com(pa, pa, ea, size, flags);
363 if (ret == NULL) {
364 printk(KERN_ERR "ioremap_explicit() allocation failure !\n");
365 return 1;
366 }
367 if (ret != (void *) ea) {
280 printk(KERN_ERR "__ioremap_com() returned unexpected addr\n"); 368 printk(KERN_ERR "__ioremap_com() returned unexpected addr\n");
281 return 1; 369 return 1;
282 } 370 }
@@ -284,69 +372,6 @@ int __ioremap_explicit(unsigned long pa, unsigned long ea,
284 return 0; 372 return 0;
285} 373}
286 374
287static void unmap_im_area_pte(pmd_t *pmd, unsigned long address,
288 unsigned long size)
289{
290 unsigned long base, end;
291 pte_t *pte;
292
293 if (pmd_none(*pmd))
294 return;
295 if (pmd_bad(*pmd)) {
296 pmd_ERROR(*pmd);
297 pmd_clear(pmd);
298 return;
299 }
300
301 pte = pte_offset_kernel(pmd, address);
302 base = address & PMD_MASK;
303 address &= ~PMD_MASK;
304 end = address + size;
305 if (end > PMD_SIZE)
306 end = PMD_SIZE;
307
308 do {
309 pte_t page;
310 page = ptep_get_and_clear(&ioremap_mm, base + address, pte);
311 address += PAGE_SIZE;
312 pte++;
313 if (pte_none(page))
314 continue;
315 if (pte_present(page))
316 continue;
317 printk(KERN_CRIT "Whee.. Swapped out page in kernel page"
318 " table\n");
319 } while (address < end);
320}
321
322static void unmap_im_area_pmd(pgd_t *dir, unsigned long address,
323 unsigned long size)
324{
325 unsigned long base, end;
326 pmd_t *pmd;
327
328 if (pgd_none(*dir))
329 return;
330 if (pgd_bad(*dir)) {
331 pgd_ERROR(*dir);
332 pgd_clear(dir);
333 return;
334 }
335
336 pmd = pmd_offset(dir, address);
337 base = address & PGDIR_MASK;
338 address &= ~PGDIR_MASK;
339 end = address + size;
340 if (end > PGDIR_SIZE)
341 end = PGDIR_SIZE;
342
343 do {
344 unmap_im_area_pte(pmd, base + address, end - address);
345 address = (address + PMD_SIZE) & PMD_MASK;
346 pmd++;
347 } while (address < end);
348}
349
350/* 375/*
351 * Unmap an IO region and remove it from imalloc'd list. 376 * Unmap an IO region and remove it from imalloc'd list.
352 * Access to IO memory should be serialized by driver. 377 * Access to IO memory should be serialized by driver.
@@ -356,39 +381,19 @@ static void unmap_im_area_pmd(pgd_t *dir, unsigned long address,
356 */ 381 */
357void iounmap(volatile void __iomem *token) 382void iounmap(volatile void __iomem *token)
358{ 383{
359 unsigned long address, start, end, size; 384 unsigned long address, size;
360 struct mm_struct *mm;
361 pgd_t *dir;
362 void *addr; 385 void *addr;
363 386
364 if (!mem_init_done) { 387 if (!mem_init_done)
365 return; 388 return;
366 }
367 389
368 addr = (void *) ((unsigned long __force) token & PAGE_MASK); 390 addr = (void *) ((unsigned long __force) token & PAGE_MASK);
369 391
370 if ((size = im_free(addr)) == 0) { 392 if ((size = im_free(addr)) == 0)
371 return; 393 return;
372 }
373 394
374 address = (unsigned long)addr; 395 address = (unsigned long)addr;
375 start = address; 396 unmap_im_area(address, address + size);
376 end = address + size;
377
378 mm = &ioremap_mm;
379 spin_lock(&mm->page_table_lock);
380
381 dir = pgd_offset_i(address);
382 flush_cache_vunmap(address, end);
383 do {
384 unmap_im_area_pmd(dir, address, end - address);
385 address = (address + PGDIR_SIZE) & PGDIR_MASK;
386 dir++;
387 } while (address && (address < end));
388 flush_tlb_kernel_range(start, end);
389
390 spin_unlock(&mm->page_table_lock);
391 return;
392} 397}
393 398
394static int iounmap_subset_regions(unsigned long addr, unsigned long size) 399static int iounmap_subset_regions(unsigned long addr, unsigned long size)
@@ -664,7 +669,7 @@ void __init paging_init(void)
664 zones_size[ZONE_DMA] = top_of_ram >> PAGE_SHIFT; 669 zones_size[ZONE_DMA] = top_of_ram >> PAGE_SHIFT;
665 zholes_size[ZONE_DMA] = (top_of_ram - total_ram) >> PAGE_SHIFT; 670 zholes_size[ZONE_DMA] = (top_of_ram - total_ram) >> PAGE_SHIFT;
666 671
667 free_area_init_node(0, &contig_page_data, zones_size, 672 free_area_init_node(0, NODE_DATA(0), zones_size,
668 __pa(PAGE_OFFSET) >> PAGE_SHIFT, zholes_size); 673 __pa(PAGE_OFFSET) >> PAGE_SHIFT, zholes_size);
669} 674}
670#endif /* CONFIG_DISCONTIGMEM */ 675#endif /* CONFIG_DISCONTIGMEM */