cache-sh7705.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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/fs.h>
  16. #include <linux/threads.h>
  17. #include <asm/addrspace.h>
  18. #include <asm/page.h>
  19. #include <asm/pgtable.h>
  20. #include <asm/processor.h>
  21. #include <asm/cache.h>
  22. #include <asm/io.h>
  23. #include <asm/uaccess.h>
  24. #include <asm/pgalloc.h>
  25. #include <asm/mmu_context.h>
  26. #include <asm/cacheflush.h>
  27. /*
  28. * The 32KB cache on the SH7705 suffers from the same synonym problem
  29. * as SH4 CPUs
  30. */
  31. static inline void cache_wback_all(void)
  32. {
  33. unsigned long ways, waysize, addrstart;
  34. ways = current_cpu_data.dcache.ways;
  35. waysize = current_cpu_data.dcache.sets;
  36. waysize <<= current_cpu_data.dcache.entry_shift;
  37. addrstart = CACHE_OC_ADDRESS_ARRAY;
  38. do {
  39. unsigned long addr;
  40. for (addr = addrstart;
  41. addr < addrstart + waysize;
  42. addr += current_cpu_data.dcache.linesz) {
  43. unsigned long data;
  44. int v = SH_CACHE_UPDATED | SH_CACHE_VALID;
  45. data = __raw_readl(addr);
  46. if ((data & v) == v)
  47. __raw_writel(data & ~v, addr);
  48. }
  49. addrstart += current_cpu_data.dcache.way_incr;
  50. } while (--ways);
  51. }
  52. /*
  53. * Write back the range of D-cache, and purge the I-cache.
  54. *
  55. * Called from kernel/module.c:sys_init_module and routine for a.out format.
  56. */
  57. static void sh7705_flush_icache_range(void *args)
  58. {
  59. struct flusher_data *data = args;
  60. unsigned long start, end;
  61. start = data->addr1;
  62. end = data->addr2;
  63. __flush_wback_region((void *)start, end - start);
  64. }
  65. /*
  66. * Writeback&Invalidate the D-cache of the page
  67. */
  68. static void __flush_dcache_page(unsigned long phys)
  69. {
  70. unsigned long ways, waysize, addrstart;
  71. unsigned long flags;
  72. phys |= SH_CACHE_VALID;
  73. /*
  74. * Here, phys is the physical address of the page. We check all the
  75. * tags in the cache for those with the same page number as this page
  76. * (by masking off the lowest 2 bits of the 19-bit tag; these bits are
  77. * derived from the offset within in the 4k page). Matching valid
  78. * entries are invalidated.
  79. *
  80. * Since 2 bits of the cache index are derived from the virtual page
  81. * number, knowing this would reduce the number of cache entries to be
  82. * searched by a factor of 4. However this function exists to deal with
  83. * potential cache aliasing, therefore the optimisation is probably not
  84. * possible.
  85. */
  86. local_irq_save(flags);
  87. jump_to_uncached();
  88. ways = current_cpu_data.dcache.ways;
  89. waysize = current_cpu_data.dcache.sets;
  90. waysize <<= current_cpu_data.dcache.entry_shift;
  91. addrstart = CACHE_OC_ADDRESS_ARRAY;
  92. do {
  93. unsigned long addr;
  94. for (addr = addrstart;
  95. addr < addrstart + waysize;
  96. addr += current_cpu_data.dcache.linesz) {
  97. unsigned long data;
  98. data = __raw_readl(addr) & (0x1ffffC00 | SH_CACHE_VALID);
  99. if (data == phys) {
  100. data &= ~(SH_CACHE_VALID | SH_CACHE_UPDATED);
  101. __raw_writel(data, addr);
  102. }
  103. }
  104. addrstart += current_cpu_data.dcache.way_incr;
  105. } while (--ways);
  106. back_to_cached();
  107. local_irq_restore(flags);
  108. }
  109. /*
  110. * Write back & invalidate the D-cache of the page.
  111. * (To avoid "alias" issues)
  112. */
  113. static void sh7705_flush_dcache_page(void *arg)
  114. {
  115. struct page *page = arg;
  116. struct address_space *mapping = page_mapping(page);
  117. if (mapping && !mapping_mapped(mapping))
  118. clear_bit(PG_dcache_clean, &page->flags);
  119. else
  120. __flush_dcache_page(__pa(page_address(page)));
  121. }
  122. static void sh7705_flush_cache_all(void *args)
  123. {
  124. unsigned long flags;
  125. local_irq_save(flags);
  126. jump_to_uncached();
  127. cache_wback_all();
  128. back_to_cached();
  129. local_irq_restore(flags);
  130. }
  131. /*
  132. * Write back and invalidate I/D-caches for the page.
  133. *
  134. * ADDRESS: Virtual Address (U0 address)
  135. */
  136. static void sh7705_flush_cache_page(void *args)
  137. {
  138. struct flusher_data *data = args;
  139. unsigned long pfn = data->addr2;
  140. __flush_dcache_page(pfn << PAGE_SHIFT);
  141. }
  142. /*
  143. * This is called when a page-cache page is about to be mapped into a
  144. * user process' address space. It offers an opportunity for a
  145. * port to ensure d-cache/i-cache coherency if necessary.
  146. *
  147. * Not entirely sure why this is necessary on SH3 with 32K cache but
  148. * without it we get occasional "Memory fault" when loading a program.
  149. */
  150. static void sh7705_flush_icache_page(void *page)
  151. {
  152. __flush_purge_region(page_address(page), PAGE_SIZE);
  153. }
  154. void __init sh7705_cache_init(void)
  155. {
  156. local_flush_icache_range = sh7705_flush_icache_range;
  157. local_flush_dcache_page = sh7705_flush_dcache_page;
  158. local_flush_cache_all = sh7705_flush_cache_all;
  159. local_flush_cache_mm = sh7705_flush_cache_all;
  160. local_flush_cache_dup_mm = sh7705_flush_cache_all;
  161. local_flush_cache_range = sh7705_flush_cache_all;
  162. local_flush_cache_page = sh7705_flush_cache_page;
  163. local_flush_icache_page = sh7705_flush_icache_page;
  164. }