cache-sh7705.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * arch/sh/mm/cache-sh7705.c
  3. *
  4. * Copyright (C) 1999, 2000 Niibe Yutaka
  5. * Copyright (C) 2004 Alex Song
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. *
  11. */
  12. #include <linux/init.h>
  13. #include <linux/mman.h>
  14. #include <linux/mm.h>
  15. #include <linux/threads.h>
  16. #include <asm/addrspace.h>
  17. #include <asm/page.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/processor.h>
  20. #include <asm/cache.h>
  21. #include <asm/io.h>
  22. #include <asm/uaccess.h>
  23. #include <asm/pgalloc.h>
  24. #include <asm/mmu_context.h>
  25. #include <asm/cacheflush.h>
  26. /*
  27. * The 32KB cache on the SH7705 suffers from the same synonym problem
  28. * as SH4 CPUs
  29. */
  30. static inline void cache_wback_all(void)
  31. {
  32. unsigned long ways, waysize, addrstart;
  33. ways = current_cpu_data.dcache.ways;
  34. waysize = current_cpu_data.dcache.sets;
  35. waysize <<= current_cpu_data.dcache.entry_shift;
  36. addrstart = CACHE_OC_ADDRESS_ARRAY;
  37. do {
  38. unsigned long addr;
  39. for (addr = addrstart;
  40. addr < addrstart + waysize;
  41. addr += current_cpu_data.dcache.linesz) {
  42. unsigned long data;
  43. int v = SH_CACHE_UPDATED | SH_CACHE_VALID;
  44. data = ctrl_inl(addr);
  45. if ((data & v) == v)
  46. ctrl_outl(data & ~v, addr);
  47. }
  48. addrstart += current_cpu_data.dcache.way_incr;
  49. } while (--ways);
  50. }
  51. /*
  52. * Write back the range of D-cache, and purge the I-cache.
  53. *
  54. * Called from kernel/module.c:sys_init_module and routine for a.out format.
  55. */
  56. void flush_icache_range(unsigned long start, unsigned long end)
  57. {
  58. __flush_wback_region((void *)start, end - start);
  59. }
  60. /*
  61. * Writeback&Invalidate the D-cache of the page
  62. */
  63. static void __uses_jump_to_uncached __flush_dcache_page(unsigned long phys)
  64. {
  65. unsigned long ways, waysize, addrstart;
  66. unsigned long flags;
  67. phys |= SH_CACHE_VALID;
  68. /*
  69. * Here, phys is the physical address of the page. We check all the
  70. * tags in the cache for those with the same page number as this page
  71. * (by masking off the lowest 2 bits of the 19-bit tag; these bits are
  72. * derived from the offset within in the 4k page). Matching valid
  73. * entries are invalidated.
  74. *
  75. * Since 2 bits of the cache index are derived from the virtual page
  76. * number, knowing this would reduce the number of cache entries to be
  77. * searched by a factor of 4. However this function exists to deal with
  78. * potential cache aliasing, therefore the optimisation is probably not
  79. * possible.
  80. */
  81. local_irq_save(flags);
  82. jump_to_uncached();
  83. ways = current_cpu_data.dcache.ways;
  84. waysize = current_cpu_data.dcache.sets;
  85. waysize <<= current_cpu_data.dcache.entry_shift;
  86. addrstart = CACHE_OC_ADDRESS_ARRAY;
  87. do {
  88. unsigned long addr;
  89. for (addr = addrstart;
  90. addr < addrstart + waysize;
  91. addr += current_cpu_data.dcache.linesz) {
  92. unsigned long data;
  93. data = ctrl_inl(addr) & (0x1ffffC00 | SH_CACHE_VALID);
  94. if (data == phys) {
  95. data &= ~(SH_CACHE_VALID | SH_CACHE_UPDATED);
  96. ctrl_outl(data, addr);
  97. }
  98. }
  99. addrstart += current_cpu_data.dcache.way_incr;
  100. } while (--ways);
  101. back_to_cached();
  102. local_irq_restore(flags);
  103. }
  104. /*
  105. * Write back & invalidate the D-cache of the page.
  106. * (To avoid "alias" issues)
  107. */
  108. void flush_dcache_page(struct page *page)
  109. {
  110. if (test_bit(PG_mapped, &page->flags))
  111. __flush_dcache_page(PHYSADDR(page_address(page)));
  112. }
  113. void __uses_jump_to_uncached flush_cache_all(void)
  114. {
  115. unsigned long flags;
  116. local_irq_save(flags);
  117. jump_to_uncached();
  118. cache_wback_all();
  119. back_to_cached();
  120. local_irq_restore(flags);
  121. }
  122. void flush_cache_mm(struct mm_struct *mm)
  123. {
  124. /* Is there any good way? */
  125. /* XXX: possibly call flush_cache_range for each vm area */
  126. flush_cache_all();
  127. }
  128. /*
  129. * Write back and invalidate D-caches.
  130. *
  131. * START, END: Virtual Address (U0 address)
  132. *
  133. * NOTE: We need to flush the _physical_ page entry.
  134. * Flushing the cache lines for U0 only isn't enough.
  135. * We need to flush for P1 too, which may contain aliases.
  136. */
  137. void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
  138. unsigned long end)
  139. {
  140. /*
  141. * We could call flush_cache_page for the pages of these range,
  142. * but it's not efficient (scan the caches all the time...).
  143. *
  144. * We can't use A-bit magic, as there's the case we don't have
  145. * valid entry on TLB.
  146. */
  147. flush_cache_all();
  148. }
  149. /*
  150. * Write back and invalidate I/D-caches for the page.
  151. *
  152. * ADDRESS: Virtual Address (U0 address)
  153. */
  154. void flush_cache_page(struct vm_area_struct *vma, unsigned long address,
  155. unsigned long pfn)
  156. {
  157. __flush_dcache_page(pfn << PAGE_SHIFT);
  158. }
  159. /*
  160. * This is called when a page-cache page is about to be mapped into a
  161. * user process' address space. It offers an opportunity for a
  162. * port to ensure d-cache/i-cache coherency if necessary.
  163. *
  164. * Not entirely sure why this is necessary on SH3 with 32K cache but
  165. * without it we get occasional "Memory fault" when loading a program.
  166. */
  167. void flush_icache_page(struct vm_area_struct *vma, struct page *page)
  168. {
  169. __flush_purge_region(page_address(page), PAGE_SIZE);
  170. }