cache-sh4.c 20 KB

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