cache-sh4.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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_one(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 __uses_jump_to_uncached sh4_flush_icache_range(void *args)
  43. {
  44. struct flusher_data *data = args;
  45. unsigned long start, end;
  46. unsigned long flags, v;
  47. int i;
  48. start = data->addr1;
  49. end = data->addr2;
  50. /* If there are too many pages then just blow away the caches */
  51. if (((end - start) >> PAGE_SHIFT) >= MAX_ICACHE_PAGES) {
  52. local_flush_cache_all(NULL);
  53. return;
  54. }
  55. /*
  56. * Selectively flush d-cache then invalidate the i-cache.
  57. * This is inefficient, so only use this for small ranges.
  58. */
  59. start &= ~(L1_CACHE_BYTES-1);
  60. end += L1_CACHE_BYTES-1;
  61. end &= ~(L1_CACHE_BYTES-1);
  62. local_irq_save(flags);
  63. jump_to_uncached();
  64. for (v = start; v < end; v += L1_CACHE_BYTES) {
  65. unsigned long icacheaddr;
  66. __ocbwb(v);
  67. icacheaddr = CACHE_IC_ADDRESS_ARRAY | (v &
  68. cpu_data->icache.entry_mask);
  69. /* Clear i-cache line valid-bit */
  70. for (i = 0; i < cpu_data->icache.ways; i++) {
  71. __raw_writel(0, icacheaddr);
  72. icacheaddr += cpu_data->icache.way_incr;
  73. }
  74. }
  75. back_to_cached();
  76. local_irq_restore(flags);
  77. }
  78. static inline void flush_cache_one(unsigned long start, 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_one(start | SH_CACHE_ASSOC, P1SEGADDR(phys), exec_offset);
  90. local_irq_restore(flags);
  91. }
  92. /*
  93. * Write back & invalidate the D-cache of the page.
  94. * (To avoid "alias" issues)
  95. */
  96. static void sh4_flush_dcache_page(void *arg)
  97. {
  98. struct page *page = arg;
  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 += PAGE_SIZE)
  112. flush_cache_one(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_one(
  267. CACHE_OC_ADDRESS_ARRAY | (address & alias_mask),
  268. phys);
  269. /* Loop another 4K of the D-cache */
  270. flush_cache_one(
  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_one(
  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_one
  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_one(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. * We want to eliminate unnecessary bus transactions, so this code uses
  403. * a non-obvious technique.
  404. *
  405. * Loop over a cache way sized block of, one cache line at a time. For each
  406. * line, use movca.a to cause the current cache line contents to be written
  407. * back, but without reading anything from main memory. However this has the
  408. * side effect that the cache is now caching that memory location. So follow
  409. * this with a cache invalidate to mark the cache line invalid. And do all
  410. * this with interrupts disabled, to avoid the cache line being accidently
  411. * evicted while it is holding garbage.
  412. *
  413. * This also breaks in a number of circumstances:
  414. * - if there are modifications to the region of memory just above
  415. * empty_zero_page (for example because a breakpoint has been placed
  416. * there), then these can be lost.
  417. *
  418. * This is because the the memory address which the cache temporarily
  419. * caches in the above description is empty_zero_page. So the
  420. * movca.l hits the cache (it is assumed that it misses, or at least
  421. * isn't dirty), modifies the line and then invalidates it, losing the
  422. * required change.
  423. *
  424. * - If caches are disabled or configured in write-through mode, then
  425. * the movca.l writes garbage directly into memory.
  426. */
  427. static void __flush_dcache_segment_writethrough(unsigned long start,
  428. unsigned long extent_per_way)
  429. {
  430. unsigned long addr;
  431. int i;
  432. addr = CACHE_OC_ADDRESS_ARRAY | (start & cpu_data->dcache.entry_mask);
  433. while (extent_per_way) {
  434. for (i = 0; i < cpu_data->dcache.ways; i++)
  435. __raw_writel(0, addr + cpu_data->dcache.way_incr * i);
  436. addr += cpu_data->dcache.linesz;
  437. extent_per_way -= cpu_data->dcache.linesz;
  438. }
  439. }
  440. static void __flush_dcache_segment_1way(unsigned long start,
  441. unsigned long extent_per_way)
  442. {
  443. unsigned long orig_sr, sr_with_bl;
  444. unsigned long base_addr;
  445. unsigned long way_incr, linesz, way_size;
  446. struct cache_info *dcache;
  447. register unsigned long a0, a0e;
  448. asm volatile("stc sr, %0" : "=r" (orig_sr));
  449. sr_with_bl = orig_sr | (1<<28);
  450. base_addr = ((unsigned long)&empty_zero_page[0]);
  451. /*
  452. * The previous code aligned base_addr to 16k, i.e. the way_size of all
  453. * existing SH-4 D-caches. Whilst I don't see a need to have this
  454. * aligned to any better than the cache line size (which it will be
  455. * anyway by construction), let's align it to at least the way_size of
  456. * any existing or conceivable SH-4 D-cache. -- RPC
  457. */
  458. base_addr = ((base_addr >> 16) << 16);
  459. base_addr |= start;
  460. dcache = &boot_cpu_data.dcache;
  461. linesz = dcache->linesz;
  462. way_incr = dcache->way_incr;
  463. way_size = dcache->way_size;
  464. a0 = base_addr;
  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. "ocbi @%0" : : "r" (a0));
  470. a0 += linesz;
  471. asm volatile("movca.l r0, @%0\n\t"
  472. "ocbi @%0" : : "r" (a0));
  473. a0 += linesz;
  474. asm volatile("movca.l r0, @%0\n\t"
  475. "ocbi @%0" : : "r" (a0));
  476. a0 += linesz;
  477. asm volatile("movca.l r0, @%0\n\t"
  478. "ocbi @%0" : : "r" (a0));
  479. asm volatile("ldc %0, sr" : : "r" (orig_sr));
  480. a0 += linesz;
  481. } while (a0 < a0e);
  482. }
  483. static void __flush_dcache_segment_2way(unsigned long start,
  484. unsigned long extent_per_way)
  485. {
  486. unsigned long orig_sr, sr_with_bl;
  487. unsigned long base_addr;
  488. unsigned long way_incr, linesz, way_size;
  489. struct cache_info *dcache;
  490. register unsigned long a0, a1, a0e;
  491. asm volatile("stc sr, %0" : "=r" (orig_sr));
  492. sr_with_bl = orig_sr | (1<<28);
  493. base_addr = ((unsigned long)&empty_zero_page[0]);
  494. /* See comment under 1-way above */
  495. base_addr = ((base_addr >> 16) << 16);
  496. base_addr |= start;
  497. dcache = &boot_cpu_data.dcache;
  498. linesz = dcache->linesz;
  499. way_incr = dcache->way_incr;
  500. way_size = dcache->way_size;
  501. a0 = base_addr;
  502. a1 = a0 + way_incr;
  503. a0e = base_addr + extent_per_way;
  504. do {
  505. asm volatile("ldc %0, sr" : : "r" (sr_with_bl));
  506. asm volatile("movca.l r0, @%0\n\t"
  507. "movca.l r0, @%1\n\t"
  508. "ocbi @%0\n\t"
  509. "ocbi @%1" : :
  510. "r" (a0), "r" (a1));
  511. a0 += linesz;
  512. a1 += linesz;
  513. asm volatile("movca.l r0, @%0\n\t"
  514. "movca.l r0, @%1\n\t"
  515. "ocbi @%0\n\t"
  516. "ocbi @%1" : :
  517. "r" (a0), "r" (a1));
  518. a0 += linesz;
  519. a1 += linesz;
  520. asm volatile("movca.l r0, @%0\n\t"
  521. "movca.l r0, @%1\n\t"
  522. "ocbi @%0\n\t"
  523. "ocbi @%1" : :
  524. "r" (a0), "r" (a1));
  525. a0 += linesz;
  526. a1 += linesz;
  527. asm volatile("movca.l r0, @%0\n\t"
  528. "movca.l r0, @%1\n\t"
  529. "ocbi @%0\n\t"
  530. "ocbi @%1" : :
  531. "r" (a0), "r" (a1));
  532. asm volatile("ldc %0, sr" : : "r" (orig_sr));
  533. a0 += linesz;
  534. a1 += linesz;
  535. } while (a0 < a0e);
  536. }
  537. static void __flush_dcache_segment_4way(unsigned long start,
  538. unsigned long extent_per_way)
  539. {
  540. unsigned long orig_sr, sr_with_bl;
  541. unsigned long base_addr;
  542. unsigned long way_incr, linesz, way_size;
  543. struct cache_info *dcache;
  544. register unsigned long a0, a1, a2, a3, a0e;
  545. asm volatile("stc sr, %0" : "=r" (orig_sr));
  546. sr_with_bl = orig_sr | (1<<28);
  547. base_addr = ((unsigned long)&empty_zero_page[0]);
  548. /* See comment under 1-way above */
  549. base_addr = ((base_addr >> 16) << 16);
  550. base_addr |= start;
  551. dcache = &boot_cpu_data.dcache;
  552. linesz = dcache->linesz;
  553. way_incr = dcache->way_incr;
  554. way_size = dcache->way_size;
  555. a0 = base_addr;
  556. a1 = a0 + way_incr;
  557. a2 = a1 + way_incr;
  558. a3 = a2 + way_incr;
  559. a0e = base_addr + extent_per_way;
  560. do {
  561. asm volatile("ldc %0, sr" : : "r" (sr_with_bl));
  562. asm volatile("movca.l r0, @%0\n\t"
  563. "movca.l r0, @%1\n\t"
  564. "movca.l r0, @%2\n\t"
  565. "movca.l r0, @%3\n\t"
  566. "ocbi @%0\n\t"
  567. "ocbi @%1\n\t"
  568. "ocbi @%2\n\t"
  569. "ocbi @%3\n\t" : :
  570. "r" (a0), "r" (a1), "r" (a2), "r" (a3));
  571. a0 += linesz;
  572. a1 += linesz;
  573. a2 += linesz;
  574. a3 += linesz;
  575. asm volatile("movca.l r0, @%0\n\t"
  576. "movca.l r0, @%1\n\t"
  577. "movca.l r0, @%2\n\t"
  578. "movca.l r0, @%3\n\t"
  579. "ocbi @%0\n\t"
  580. "ocbi @%1\n\t"
  581. "ocbi @%2\n\t"
  582. "ocbi @%3\n\t" : :
  583. "r" (a0), "r" (a1), "r" (a2), "r" (a3));
  584. a0 += linesz;
  585. a1 += linesz;
  586. a2 += linesz;
  587. a3 += linesz;
  588. asm volatile("movca.l r0, @%0\n\t"
  589. "movca.l r0, @%1\n\t"
  590. "movca.l r0, @%2\n\t"
  591. "movca.l r0, @%3\n\t"
  592. "ocbi @%0\n\t"
  593. "ocbi @%1\n\t"
  594. "ocbi @%2\n\t"
  595. "ocbi @%3\n\t" : :
  596. "r" (a0), "r" (a1), "r" (a2), "r" (a3));
  597. a0 += linesz;
  598. a1 += linesz;
  599. a2 += linesz;
  600. a3 += linesz;
  601. asm volatile("movca.l r0, @%0\n\t"
  602. "movca.l r0, @%1\n\t"
  603. "movca.l r0, @%2\n\t"
  604. "movca.l r0, @%3\n\t"
  605. "ocbi @%0\n\t"
  606. "ocbi @%1\n\t"
  607. "ocbi @%2\n\t"
  608. "ocbi @%3\n\t" : :
  609. "r" (a0), "r" (a1), "r" (a2), "r" (a3));
  610. asm volatile("ldc %0, sr" : : "r" (orig_sr));
  611. a0 += linesz;
  612. a1 += linesz;
  613. a2 += linesz;
  614. a3 += linesz;
  615. } while (a0 < a0e);
  616. }
  617. extern void __weak sh4__flush_region_init(void);
  618. /*
  619. * SH-4 has virtually indexed and physically tagged cache.
  620. */
  621. void __init sh4_cache_init(void)
  622. {
  623. unsigned int wt_enabled = !!(__raw_readl(CCR) & CCR_CACHE_WT);
  624. printk("PVR=%08x CVR=%08x PRR=%08x\n",
  625. ctrl_inl(CCN_PVR),
  626. ctrl_inl(CCN_CVR),
  627. ctrl_inl(CCN_PRR));
  628. if (wt_enabled)
  629. __flush_dcache_segment_fn = __flush_dcache_segment_writethrough;
  630. else {
  631. switch (boot_cpu_data.dcache.ways) {
  632. case 1:
  633. __flush_dcache_segment_fn = __flush_dcache_segment_1way;
  634. break;
  635. case 2:
  636. __flush_dcache_segment_fn = __flush_dcache_segment_2way;
  637. break;
  638. case 4:
  639. __flush_dcache_segment_fn = __flush_dcache_segment_4way;
  640. break;
  641. default:
  642. panic("unknown number of cache ways\n");
  643. break;
  644. }
  645. }
  646. local_flush_icache_range = sh4_flush_icache_range;
  647. local_flush_dcache_page = sh4_flush_dcache_page;
  648. local_flush_cache_all = sh4_flush_cache_all;
  649. local_flush_cache_mm = sh4_flush_cache_mm;
  650. local_flush_cache_dup_mm = sh4_flush_cache_mm;
  651. local_flush_cache_page = sh4_flush_cache_page;
  652. local_flush_cache_range = sh4_flush_cache_range;
  653. sh4__flush_region_init();
  654. }