cache-sh4.c 19 KB

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