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