aa4f62f0e374a5c4d65e470b623c670e6274287c
[pandora-kernel.git] / arch / sh / mm / cache-sh4.c
1 /*
2  * arch/sh/mm/cache-sh4.c
3  *
4  * Copyright (C) 1999, 2000, 2002  Niibe Yutaka
5  * Copyright (C) 2001 - 2006  Paul Mundt
6  * Copyright (C) 2003  Richard Curnow
7  *
8  * This file is subject to the terms and conditions of the GNU General Public
9  * License.  See the file "COPYING" in the main directory of this archive
10  * for more details.
11  */
12 #include <linux/init.h>
13 #include <linux/mm.h>
14 #include <asm/addrspace.h>
15 #include <asm/pgtable.h>
16 #include <asm/processor.h>
17 #include <asm/cache.h>
18 #include <asm/io.h>
19 #include <asm/pgalloc.h>
20 #include <asm/mmu_context.h>
21 #include <asm/cacheflush.h>
22
23 /*
24  * The maximum number of pages we support up to when doing ranged dcache
25  * flushing. Anything exceeding this will simply flush the dcache in its
26  * entirety.
27  */
28 #define MAX_DCACHE_PAGES        64      /* XXX: Tune for ways */
29
30 static void __flush_dcache_segment_1way(unsigned long start,
31                                         unsigned long extent);
32 static void __flush_dcache_segment_2way(unsigned long start,
33                                         unsigned long extent);
34 static void __flush_dcache_segment_4way(unsigned long start,
35                                         unsigned long extent);
36
37 static void __flush_cache_4096(unsigned long addr, unsigned long phys,
38                                unsigned long exec_offset);
39
40 /*
41  * This is initialised here to ensure that it is not placed in the BSS.  If
42  * that were to happen, note that cache_init gets called before the BSS is
43  * cleared, so this would get nulled out which would be hopeless.
44  */
45 static void (*__flush_dcache_segment_fn)(unsigned long, unsigned long) =
46         (void (*)(unsigned long, unsigned long))0xdeadbeef;
47
48 static void compute_alias(struct cache_info *c)
49 {
50         c->alias_mask = ((c->sets - 1) << c->entry_shift) & ~(PAGE_SIZE - 1);
51         c->n_aliases = (c->alias_mask >> PAGE_SHIFT) + 1;
52 }
53
54 static void __init emit_cache_params(void)
55 {
56         printk("PVR=%08x CVR=%08x PRR=%08x\n",
57                 ctrl_inl(CCN_PVR),
58                 ctrl_inl(CCN_CVR),
59                 ctrl_inl(CCN_PRR));
60         printk("I-cache : n_ways=%d n_sets=%d way_incr=%d\n",
61                 cpu_data->icache.ways,
62                 cpu_data->icache.sets,
63                 cpu_data->icache.way_incr);
64         printk("I-cache : entry_mask=0x%08x alias_mask=0x%08x n_aliases=%d\n",
65                 cpu_data->icache.entry_mask,
66                 cpu_data->icache.alias_mask,
67                 cpu_data->icache.n_aliases);
68         printk("D-cache : n_ways=%d n_sets=%d way_incr=%d\n",
69                 cpu_data->dcache.ways,
70                 cpu_data->dcache.sets,
71                 cpu_data->dcache.way_incr);
72         printk("D-cache : entry_mask=0x%08x alias_mask=0x%08x n_aliases=%d\n",
73                 cpu_data->dcache.entry_mask,
74                 cpu_data->dcache.alias_mask,
75                 cpu_data->dcache.n_aliases);
76
77         if (!__flush_dcache_segment_fn)
78                 panic("unknown number of cache ways\n");
79 }
80
81 /*
82  * SH-4 has virtually indexed and physically tagged cache.
83  */
84
85 /* Worst case assumed to be 64k cache, direct-mapped i.e. 4 synonym bits. */
86 #define MAX_P3_SEMAPHORES 16
87
88 struct semaphore p3map_sem[MAX_P3_SEMAPHORES];
89
90 void __init p3_cache_init(void)
91 {
92         int i;
93
94         compute_alias(&cpu_data->icache);
95         compute_alias(&cpu_data->dcache);
96
97         switch (cpu_data->dcache.ways) {
98         case 1:
99                 __flush_dcache_segment_fn = __flush_dcache_segment_1way;
100                 break;
101         case 2:
102                 __flush_dcache_segment_fn = __flush_dcache_segment_2way;
103                 break;
104         case 4:
105                 __flush_dcache_segment_fn = __flush_dcache_segment_4way;
106                 break;
107         default:
108                 __flush_dcache_segment_fn = NULL;
109                 break;
110         }
111
112         emit_cache_params();
113
114         if (remap_area_pages(P3SEG, 0, PAGE_SIZE * 4, _PAGE_CACHABLE))
115                 panic("%s failed.", __FUNCTION__);
116
117         for (i = 0; i < cpu_data->dcache.n_aliases; i++)
118                 sema_init(&p3map_sem[i], 1);
119 }
120
121 /*
122  * Write back the dirty D-caches, but not invalidate them.
123  *
124  * START: Virtual Address (U0, P1, or P3)
125  * SIZE: Size of the region.
126  */
127 void __flush_wback_region(void *start, int size)
128 {
129         unsigned long v;
130         unsigned long begin, end;
131
132         begin = (unsigned long)start & ~(L1_CACHE_BYTES-1);
133         end = ((unsigned long)start + size + L1_CACHE_BYTES-1)
134                 & ~(L1_CACHE_BYTES-1);
135         for (v = begin; v < end; v+=L1_CACHE_BYTES) {
136                 asm volatile("ocbwb     %0"
137                              : /* no output */
138                              : "m" (__m(v)));
139         }
140 }
141
142 /*
143  * Write back the dirty D-caches and invalidate them.
144  *
145  * START: Virtual Address (U0, P1, or P3)
146  * SIZE: Size of the region.
147  */
148 void __flush_purge_region(void *start, int size)
149 {
150         unsigned long v;
151         unsigned long begin, end;
152
153         begin = (unsigned long)start & ~(L1_CACHE_BYTES-1);
154         end = ((unsigned long)start + size + L1_CACHE_BYTES-1)
155                 & ~(L1_CACHE_BYTES-1);
156         for (v = begin; v < end; v+=L1_CACHE_BYTES) {
157                 asm volatile("ocbp      %0"
158                              : /* no output */
159                              : "m" (__m(v)));
160         }
161 }
162
163 /*
164  * No write back please
165  */
166 void __flush_invalidate_region(void *start, int size)
167 {
168         unsigned long v;
169         unsigned long begin, end;
170
171         begin = (unsigned long)start & ~(L1_CACHE_BYTES-1);
172         end = ((unsigned long)start + size + L1_CACHE_BYTES-1)
173                 & ~(L1_CACHE_BYTES-1);
174         for (v = begin; v < end; v+=L1_CACHE_BYTES) {
175                 asm volatile("ocbi      %0"
176                              : /* no output */
177                              : "m" (__m(v)));
178         }
179 }
180
181 /*
182  * Write back the range of D-cache, and purge the I-cache.
183  *
184  * Called from kernel/module.c:sys_init_module and routine for a.out format.
185  */
186 void flush_icache_range(unsigned long start, unsigned long end)
187 {
188         flush_cache_all();
189 }
190
191 /*
192  * Write back the D-cache and purge the I-cache for signal trampoline.
193  * .. which happens to be the same behavior as flush_icache_range().
194  * So, we simply flush out a line.
195  */
196 void flush_cache_sigtramp(unsigned long addr)
197 {
198         unsigned long v, index;
199         unsigned long flags;
200         int i;
201
202         v = addr & ~(L1_CACHE_BYTES-1);
203         asm volatile("ocbwb     %0"
204                      : /* no output */
205                      : "m" (__m(v)));
206
207         index = CACHE_IC_ADDRESS_ARRAY | (v & cpu_data->icache.entry_mask);
208
209         local_irq_save(flags);
210         jump_to_P2();
211
212         for (i = 0; i < cpu_data->icache.ways;
213              i++, index += cpu_data->icache.way_incr)
214                 ctrl_outl(0, index);    /* Clear out Valid-bit */
215
216         back_to_P1();
217         wmb();
218         local_irq_restore(flags);
219 }
220
221 static inline void flush_cache_4096(unsigned long start,
222                                     unsigned long phys)
223 {
224         /*
225          * All types of SH-4 require PC to be in P2 to operate on the I-cache.
226          * Some types of SH-4 require PC to be in P2 to operate on the D-cache.
227          */
228         if ((cpu_data->flags & CPU_HAS_P2_FLUSH_BUG) ||
229             (start < CACHE_OC_ADDRESS_ARRAY)) {
230                 unsigned long flags;
231
232                 local_irq_save(flags);
233                 __flush_cache_4096(start | SH_CACHE_ASSOC,
234                                    P1SEGADDR(phys), 0x20000000);
235                 local_irq_restore(flags);
236         } else {
237                 __flush_cache_4096(start | SH_CACHE_ASSOC,
238                                    P1SEGADDR(phys), 0);
239         }
240 }
241
242 /*
243  * Write back & invalidate the D-cache of the page.
244  * (To avoid "alias" issues)
245  */
246 void flush_dcache_page(struct page *page)
247 {
248         if (test_bit(PG_mapped, &page->flags)) {
249                 unsigned long phys = PHYSADDR(page_address(page));
250                 unsigned long addr = CACHE_OC_ADDRESS_ARRAY;
251                 int i, n;
252
253                 /* Loop all the D-cache */
254                 n = cpu_data->dcache.n_aliases;
255                 for (i = 0; i < n; i++, addr += PAGE_SIZE)
256                         flush_cache_4096(addr, phys);
257         }
258
259         wmb();
260 }
261
262 /* TODO: Selective icache invalidation through IC address array.. */
263 static inline void flush_icache_all(void)
264 {
265         unsigned long flags, ccr;
266
267         local_irq_save(flags);
268         jump_to_P2();
269
270         /* Flush I-cache */
271         ccr = ctrl_inl(CCR);
272         ccr |= CCR_CACHE_ICI;
273         ctrl_outl(ccr, CCR);
274
275         /*
276          * back_to_P1() will take care of the barrier for us, don't add
277          * another one!
278          */
279
280         back_to_P1();
281         local_irq_restore(flags);
282 }
283
284 void flush_dcache_all(void)
285 {
286         (*__flush_dcache_segment_fn)(0UL, cpu_data->dcache.way_size);
287         wmb();
288 }
289
290 void flush_cache_all(void)
291 {
292         flush_dcache_all();
293         flush_icache_all();
294 }
295
296 static void __flush_cache_mm(struct mm_struct *mm, unsigned long start,
297                              unsigned long end)
298 {
299         unsigned long d = 0, p = start & PAGE_MASK;
300         unsigned long alias_mask = cpu_data->dcache.alias_mask;
301         unsigned long n_aliases = cpu_data->dcache.n_aliases;
302         unsigned long select_bit;
303         unsigned long all_aliases_mask;
304         unsigned long addr_offset;
305         pgd_t *dir;
306         pmd_t *pmd;
307         pud_t *pud;
308         pte_t *pte;
309         int i;
310
311         dir = pgd_offset(mm, p);
312         pud = pud_offset(dir, p);
313         pmd = pmd_offset(pud, p);
314         end = PAGE_ALIGN(end);
315
316         all_aliases_mask = (1 << n_aliases) - 1;
317
318         do {
319                 if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd))) {
320                         p &= PMD_MASK;
321                         p += PMD_SIZE;
322                         pmd++;
323
324                         continue;
325                 }
326
327                 pte = pte_offset_kernel(pmd, p);
328
329                 do {
330                         unsigned long phys;
331                         pte_t entry = *pte;
332
333                         if (!(pte_val(entry) & _PAGE_PRESENT)) {
334                                 pte++;
335                                 p += PAGE_SIZE;
336                                 continue;
337                         }
338
339                         phys = pte_val(entry) & PTE_PHYS_MASK;
340
341                         if ((p ^ phys) & alias_mask) {
342                                 d |= 1 << ((p & alias_mask) >> PAGE_SHIFT);
343                                 d |= 1 << ((phys & alias_mask) >> PAGE_SHIFT);
344
345                                 if (d == all_aliases_mask)
346                                         goto loop_exit;
347                         }
348
349                         pte++;
350                         p += PAGE_SIZE;
351                 } while (p < end && ((unsigned long)pte & ~PAGE_MASK));
352                 pmd++;
353         } while (p < end);
354
355 loop_exit:
356         addr_offset = 0;
357         select_bit = 1;
358
359         for (i = 0; i < n_aliases; i++) {
360                 if (d & select_bit) {
361                         (*__flush_dcache_segment_fn)(addr_offset, PAGE_SIZE);
362                         wmb();
363                 }
364
365                 select_bit <<= 1;
366                 addr_offset += PAGE_SIZE;
367         }
368 }
369
370 /*
371  * Note : (RPC) since the caches are physically tagged, the only point
372  * of flush_cache_mm for SH-4 is to get rid of aliases from the
373  * D-cache.  The assumption elsewhere, e.g. flush_cache_range, is that
374  * lines can stay resident so long as the virtual address they were
375  * accessed with (hence cache set) is in accord with the physical
376  * address (i.e. tag).  It's no different here.  So I reckon we don't
377  * need to flush the I-cache, since aliases don't matter for that.  We
378  * should try that.
379  *
380  * Caller takes mm->mmap_sem.
381  */
382 void flush_cache_mm(struct mm_struct *mm)
383 {
384         /*
385          * If cache is only 4k-per-way, there are never any 'aliases'.  Since
386          * the cache is physically tagged, the data can just be left in there.
387          */
388         if (cpu_data->dcache.n_aliases == 0)
389                 return;
390
391         /*
392          * Don't bother groveling around the dcache for the VMA ranges
393          * if there are too many PTEs to make it worthwhile.
394          */
395         if (mm->nr_ptes >= MAX_DCACHE_PAGES)
396                 flush_dcache_all();
397         else {
398                 struct vm_area_struct *vma;
399
400                 /*
401                  * In this case there are reasonably sized ranges to flush,
402                  * iterate through the VMA list and take care of any aliases.
403                  */
404                 for (vma = mm->mmap; vma; vma = vma->vm_next)
405                         __flush_cache_mm(mm, vma->vm_start, vma->vm_end);
406         }
407
408         /* Only touch the icache if one of the VMAs has VM_EXEC set. */
409         if (mm->exec_vm)
410                 flush_icache_all();
411 }
412
413 /*
414  * Write back and invalidate I/D-caches for the page.
415  *
416  * ADDR: Virtual Address (U0 address)
417  * PFN: Physical page number
418  */
419 void flush_cache_page(struct vm_area_struct *vma, unsigned long address,
420                       unsigned long pfn)
421 {
422         unsigned long phys = pfn << PAGE_SHIFT;
423         unsigned int alias_mask;
424
425         alias_mask = cpu_data->dcache.alias_mask;
426
427         /* We only need to flush D-cache when we have alias */
428         if ((address^phys) & alias_mask) {
429                 /* Loop 4K of the D-cache */
430                 flush_cache_4096(
431                         CACHE_OC_ADDRESS_ARRAY | (address & alias_mask),
432                         phys);
433                 /* Loop another 4K of the D-cache */
434                 flush_cache_4096(
435                         CACHE_OC_ADDRESS_ARRAY | (phys & alias_mask),
436                         phys);
437         }
438
439         alias_mask = cpu_data->icache.alias_mask;
440         if (vma->vm_flags & VM_EXEC) {
441                 /*
442                  * Evict entries from the portion of the cache from which code
443                  * may have been executed at this address (virtual).  There's
444                  * no need to evict from the portion corresponding to the
445                  * physical address as for the D-cache, because we know the
446                  * kernel has never executed the code through its identity
447                  * translation.
448                  */
449                 flush_cache_4096(
450                         CACHE_IC_ADDRESS_ARRAY | (address & alias_mask),
451                         phys);
452         }
453 }
454
455 /*
456  * Write back and invalidate D-caches.
457  *
458  * START, END: Virtual Address (U0 address)
459  *
460  * NOTE: We need to flush the _physical_ page entry.
461  * Flushing the cache lines for U0 only isn't enough.
462  * We need to flush for P1 too, which may contain aliases.
463  */
464 void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
465                        unsigned long end)
466 {
467         /*
468          * If cache is only 4k-per-way, there are never any 'aliases'.  Since
469          * the cache is physically tagged, the data can just be left in there.
470          */
471         if (cpu_data->dcache.n_aliases == 0)
472                 return;
473
474         /*
475          * Don't bother with the lookup and alias check if we have a
476          * wide range to cover, just blow away the dcache in its
477          * entirety instead. -- PFM.
478          */
479         if (((end - start) >> PAGE_SHIFT) >= MAX_DCACHE_PAGES)
480                 flush_dcache_all();
481         else
482                 __flush_cache_mm(vma->vm_mm, start, end);
483
484         if (vma->vm_flags & VM_EXEC) {
485                 /*
486                  * TODO: Is this required???  Need to look at how I-cache
487                  * coherency is assured when new programs are loaded to see if
488                  * this matters.
489                  */
490                 flush_icache_all();
491         }
492 }
493
494 /*
495  * flush_icache_user_range
496  * @vma: VMA of the process
497  * @page: page
498  * @addr: U0 address
499  * @len: length of the range (< page size)
500  */
501 void flush_icache_user_range(struct vm_area_struct *vma,
502                              struct page *page, unsigned long addr, int len)
503 {
504         flush_cache_page(vma, addr, page_to_pfn(page));
505         mb();
506 }
507
508 /**
509  * __flush_cache_4096
510  *
511  * @addr:  address in memory mapped cache array
512  * @phys:  P1 address to flush (has to match tags if addr has 'A' bit
513  *         set i.e. associative write)
514  * @exec_offset: set to 0x20000000 if flush has to be executed from P2
515  *               region else 0x0
516  *
517  * The offset into the cache array implied by 'addr' selects the
518  * 'colour' of the virtual address range that will be flushed.  The
519  * operation (purge/write-back) is selected by the lower 2 bits of
520  * 'phys'.
521  */
522 static void __flush_cache_4096(unsigned long addr, unsigned long phys,
523                                unsigned long exec_offset)
524 {
525         int way_count;
526         unsigned long base_addr = addr;
527         struct cache_info *dcache;
528         unsigned long way_incr;
529         unsigned long a, ea, p;
530         unsigned long temp_pc;
531
532         dcache = &cpu_data->dcache;
533         /* Write this way for better assembly. */
534         way_count = dcache->ways;
535         way_incr = dcache->way_incr;
536
537         /*
538          * Apply exec_offset (i.e. branch to P2 if required.).
539          *
540          * FIXME:
541          *
542          *      If I write "=r" for the (temp_pc), it puts this in r6 hence
543          *      trashing exec_offset before it's been added on - why?  Hence
544          *      "=&r" as a 'workaround'
545          */
546         asm volatile("mov.l 1f, %0\n\t"
547                      "add   %1, %0\n\t"
548                      "jmp   @%0\n\t"
549                      "nop\n\t"
550                      ".balign 4\n\t"
551                      "1:  .long 2f\n\t"
552                      "2:\n" : "=&r" (temp_pc) : "r" (exec_offset));
553
554         /*
555          * We know there will be >=1 iteration, so write as do-while to avoid
556          * pointless nead-of-loop check for 0 iterations.
557          */
558         do {
559                 ea = base_addr + PAGE_SIZE;
560                 a = base_addr;
561                 p = phys;
562
563                 do {
564                         *(volatile unsigned long *)a = p;
565                         /*
566                          * Next line: intentionally not p+32, saves an add, p
567                          * will do since only the cache tag bits need to
568                          * match.
569                          */
570                         *(volatile unsigned long *)(a+32) = p;
571                         a += 64;
572                         p += 64;
573                 } while (a < ea);
574
575                 base_addr += way_incr;
576         } while (--way_count != 0);
577 }
578
579 /*
580  * Break the 1, 2 and 4 way variants of this out into separate functions to
581  * avoid nearly all the overhead of having the conditional stuff in the function
582  * bodies (+ the 1 and 2 way cases avoid saving any registers too).
583  */
584 static void __flush_dcache_segment_1way(unsigned long start,
585                                         unsigned long extent_per_way)
586 {
587         unsigned long orig_sr, sr_with_bl;
588         unsigned long base_addr;
589         unsigned long way_incr, linesz, way_size;
590         struct cache_info *dcache;
591         register unsigned long a0, a0e;
592
593         asm volatile("stc sr, %0" : "=r" (orig_sr));
594         sr_with_bl = orig_sr | (1<<28);
595         base_addr = ((unsigned long)&empty_zero_page[0]);
596
597         /*
598          * The previous code aligned base_addr to 16k, i.e. the way_size of all
599          * existing SH-4 D-caches.  Whilst I don't see a need to have this
600          * aligned to any better than the cache line size (which it will be
601          * anyway by construction), let's align it to at least the way_size of
602          * any existing or conceivable SH-4 D-cache.  -- RPC
603          */
604         base_addr = ((base_addr >> 16) << 16);
605         base_addr |= start;
606
607         dcache = &cpu_data->dcache;
608         linesz = dcache->linesz;
609         way_incr = dcache->way_incr;
610         way_size = dcache->way_size;
611
612         a0 = base_addr;
613         a0e = base_addr + extent_per_way;
614         do {
615                 asm volatile("ldc %0, sr" : : "r" (sr_with_bl));
616                 asm volatile("movca.l r0, @%0\n\t"
617                              "ocbi @%0" : : "r" (a0));
618                 a0 += linesz;
619                 asm volatile("movca.l r0, @%0\n\t"
620                              "ocbi @%0" : : "r" (a0));
621                 a0 += linesz;
622                 asm volatile("movca.l r0, @%0\n\t"
623                              "ocbi @%0" : : "r" (a0));
624                 a0 += linesz;
625                 asm volatile("movca.l r0, @%0\n\t"
626                              "ocbi @%0" : : "r" (a0));
627                 asm volatile("ldc %0, sr" : : "r" (orig_sr));
628                 a0 += linesz;
629         } while (a0 < a0e);
630 }
631
632 static void __flush_dcache_segment_2way(unsigned long start,
633                                         unsigned long extent_per_way)
634 {
635         unsigned long orig_sr, sr_with_bl;
636         unsigned long base_addr;
637         unsigned long way_incr, linesz, way_size;
638         struct cache_info *dcache;
639         register unsigned long a0, a1, a0e;
640
641         asm volatile("stc sr, %0" : "=r" (orig_sr));
642         sr_with_bl = orig_sr | (1<<28);
643         base_addr = ((unsigned long)&empty_zero_page[0]);
644
645         /* See comment under 1-way above */
646         base_addr = ((base_addr >> 16) << 16);
647         base_addr |= start;
648
649         dcache = &cpu_data->dcache;
650         linesz = dcache->linesz;
651         way_incr = dcache->way_incr;
652         way_size = dcache->way_size;
653
654         a0 = base_addr;
655         a1 = a0 + way_incr;
656         a0e = base_addr + extent_per_way;
657         do {
658                 asm volatile("ldc %0, sr" : : "r" (sr_with_bl));
659                 asm volatile("movca.l r0, @%0\n\t"
660                              "movca.l r0, @%1\n\t"
661                              "ocbi @%0\n\t"
662                              "ocbi @%1" : :
663                              "r" (a0), "r" (a1));
664                 a0 += linesz;
665                 a1 += linesz;
666                 asm volatile("movca.l r0, @%0\n\t"
667                              "movca.l r0, @%1\n\t"
668                              "ocbi @%0\n\t"
669                              "ocbi @%1" : :
670                              "r" (a0), "r" (a1));
671                 a0 += linesz;
672                 a1 += linesz;
673                 asm volatile("movca.l r0, @%0\n\t"
674                              "movca.l r0, @%1\n\t"
675                              "ocbi @%0\n\t"
676                              "ocbi @%1" : :
677                              "r" (a0), "r" (a1));
678                 a0 += linesz;
679                 a1 += linesz;
680                 asm volatile("movca.l r0, @%0\n\t"
681                              "movca.l r0, @%1\n\t"
682                              "ocbi @%0\n\t"
683                              "ocbi @%1" : :
684                              "r" (a0), "r" (a1));
685                 asm volatile("ldc %0, sr" : : "r" (orig_sr));
686                 a0 += linesz;
687                 a1 += linesz;
688         } while (a0 < a0e);
689 }
690
691 static void __flush_dcache_segment_4way(unsigned long start,
692                                         unsigned long extent_per_way)
693 {
694         unsigned long orig_sr, sr_with_bl;
695         unsigned long base_addr;
696         unsigned long way_incr, linesz, way_size;
697         struct cache_info *dcache;
698         register unsigned long a0, a1, a2, a3, a0e;
699
700         asm volatile("stc sr, %0" : "=r" (orig_sr));
701         sr_with_bl = orig_sr | (1<<28);
702         base_addr = ((unsigned long)&empty_zero_page[0]);
703
704         /* See comment under 1-way above */
705         base_addr = ((base_addr >> 16) << 16);
706         base_addr |= start;
707
708         dcache = &cpu_data->dcache;
709         linesz = dcache->linesz;
710         way_incr = dcache->way_incr;
711         way_size = dcache->way_size;
712
713         a0 = base_addr;
714         a1 = a0 + way_incr;
715         a2 = a1 + way_incr;
716         a3 = a2 + way_incr;
717         a0e = base_addr + extent_per_way;
718         do {
719                 asm volatile("ldc %0, sr" : : "r" (sr_with_bl));
720                 asm volatile("movca.l r0, @%0\n\t"
721                              "movca.l r0, @%1\n\t"
722                              "movca.l r0, @%2\n\t"
723                              "movca.l r0, @%3\n\t"
724                              "ocbi @%0\n\t"
725                              "ocbi @%1\n\t"
726                              "ocbi @%2\n\t"
727                              "ocbi @%3\n\t" : :
728                              "r" (a0), "r" (a1), "r" (a2), "r" (a3));
729                 a0 += linesz;
730                 a1 += linesz;
731                 a2 += linesz;
732                 a3 += linesz;
733                 asm volatile("movca.l r0, @%0\n\t"
734                              "movca.l r0, @%1\n\t"
735                              "movca.l r0, @%2\n\t"
736                              "movca.l r0, @%3\n\t"
737                              "ocbi @%0\n\t"
738                              "ocbi @%1\n\t"
739                              "ocbi @%2\n\t"
740                              "ocbi @%3\n\t" : :
741                              "r" (a0), "r" (a1), "r" (a2), "r" (a3));
742                 a0 += linesz;
743                 a1 += linesz;
744                 a2 += linesz;
745                 a3 += linesz;
746                 asm volatile("movca.l r0, @%0\n\t"
747                              "movca.l r0, @%1\n\t"
748                              "movca.l r0, @%2\n\t"
749                              "movca.l r0, @%3\n\t"
750                              "ocbi @%0\n\t"
751                              "ocbi @%1\n\t"
752                              "ocbi @%2\n\t"
753                              "ocbi @%3\n\t" : :
754                              "r" (a0), "r" (a1), "r" (a2), "r" (a3));
755                 a0 += linesz;
756                 a1 += linesz;
757                 a2 += linesz;
758                 a3 += linesz;
759                 asm volatile("movca.l r0, @%0\n\t"
760                              "movca.l r0, @%1\n\t"
761                              "movca.l r0, @%2\n\t"
762                              "movca.l r0, @%3\n\t"
763                              "ocbi @%0\n\t"
764                              "ocbi @%1\n\t"
765                              "ocbi @%2\n\t"
766                              "ocbi @%3\n\t" : :
767                              "r" (a0), "r" (a1), "r" (a2), "r" (a3));
768                 asm volatile("ldc %0, sr" : : "r" (orig_sr));
769                 a0 += linesz;
770                 a1 += linesz;
771                 a2 += linesz;
772                 a3 += linesz;
773         } while (a0 < a0e);
774 }