cache-sh4.c 18 KB

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