cache-sh4.c 19 KB

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