cache-sh4.c 19 KB

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