memory.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/m68k/mm/memory.c
  4. *
  5. * Copyright (C) 1995 Hamish Macdonald
  6. */
  7. #include <linux/module.h>
  8. #include <linux/mm.h>
  9. #include <linux/kernel.h>
  10. #include <linux/string.h>
  11. #include <linux/types.h>
  12. #include <linux/init.h>
  13. #include <linux/pagemap.h>
  14. #include <linux/gfp.h>
  15. #include <asm/setup.h>
  16. #include <asm/page.h>
  17. #include <asm/traps.h>
  18. #include <asm/machdep.h>
  19. /* invalidate page in both caches */
  20. static inline void clear040(unsigned long paddr)
  21. {
  22. asm volatile (
  23. "nop\n\t"
  24. ".chip 68040\n\t"
  25. "cinvp %%bc,(%0)\n\t"
  26. ".chip 68k"
  27. : : "a" (paddr));
  28. }
  29. /* invalidate page in i-cache */
  30. static inline void cleari040(unsigned long paddr)
  31. {
  32. asm volatile (
  33. "nop\n\t"
  34. ".chip 68040\n\t"
  35. "cinvp %%ic,(%0)\n\t"
  36. ".chip 68k"
  37. : : "a" (paddr));
  38. }
  39. /* push page in both caches */
  40. /* RZ: cpush %bc DOES invalidate %ic, regardless of DPI */
  41. static inline void push040(unsigned long paddr)
  42. {
  43. asm volatile (
  44. "nop\n\t"
  45. ".chip 68040\n\t"
  46. "cpushp %%bc,(%0)\n\t"
  47. ".chip 68k"
  48. : : "a" (paddr));
  49. }
  50. /* push and invalidate page in both caches, must disable ints
  51. * to avoid invalidating valid data */
  52. static inline void pushcl040(unsigned long paddr)
  53. {
  54. unsigned long flags;
  55. local_irq_save(flags);
  56. push040(paddr);
  57. if (CPU_IS_060)
  58. clear040(paddr);
  59. local_irq_restore(flags);
  60. }
  61. /*
  62. * 040: Hit every page containing an address in the range paddr..paddr+len-1.
  63. * (Low order bits of the ea of a CINVP/CPUSHP are "don't care"s).
  64. * Hit every page until there is a page or less to go. Hit the next page,
  65. * and the one after that if the range hits it.
  66. */
  67. /* ++roman: A little bit more care is required here: The CINVP instruction
  68. * invalidates cache entries WITHOUT WRITING DIRTY DATA BACK! So the beginning
  69. * and the end of the region must be treated differently if they are not
  70. * exactly at the beginning or end of a page boundary. Else, maybe too much
  71. * data becomes invalidated and thus lost forever. CPUSHP does what we need:
  72. * it invalidates the page after pushing dirty data to memory. (Thanks to Jes
  73. * for discovering the problem!)
  74. */
  75. /* ... but on the '060, CPUSH doesn't invalidate (for us, since we have set
  76. * the DPI bit in the CACR; would it cause problems with temporarily changing
  77. * this?). So we have to push first and then additionally to invalidate.
  78. */
  79. /*
  80. * cache_clear() semantics: Clear any cache entries for the area in question,
  81. * without writing back dirty entries first. This is useful if the data will
  82. * be overwritten anyway, e.g. by DMA to memory. The range is defined by a
  83. * _physical_ address.
  84. */
  85. void cache_clear (unsigned long paddr, int len)
  86. {
  87. if (CPU_IS_COLDFIRE) {
  88. clear_cf_bcache(0, DCACHE_MAX_ADDR);
  89. } else if (CPU_IS_040_OR_060) {
  90. int tmp;
  91. /*
  92. * We need special treatment for the first page, in case it
  93. * is not page-aligned. Page align the addresses to work
  94. * around bug I17 in the 68060.
  95. */
  96. if ((tmp = -paddr & (PAGE_SIZE - 1))) {
  97. pushcl040(paddr & PAGE_MASK);
  98. if ((len -= tmp) <= 0)
  99. return;
  100. paddr += tmp;
  101. }
  102. tmp = PAGE_SIZE;
  103. paddr &= PAGE_MASK;
  104. while ((len -= tmp) >= 0) {
  105. clear040(paddr);
  106. paddr += tmp;
  107. }
  108. if ((len += tmp))
  109. /* a page boundary gets crossed at the end */
  110. pushcl040(paddr);
  111. }
  112. else /* 68030 or 68020 */
  113. asm volatile ("movec %/cacr,%/d0\n\t"
  114. "oriw %0,%/d0\n\t"
  115. "movec %/d0,%/cacr"
  116. : : "i" (FLUSH_I_AND_D)
  117. : "d0");
  118. #ifdef CONFIG_M68K_L2_CACHE
  119. if(mach_l2_flush)
  120. mach_l2_flush(0);
  121. #endif
  122. }
  123. EXPORT_SYMBOL(cache_clear);
  124. /*
  125. * cache_push() semantics: Write back any dirty cache data in the given area,
  126. * and invalidate the range in the instruction cache. It needs not (but may)
  127. * invalidate those entries also in the data cache. The range is defined by a
  128. * _physical_ address.
  129. */
  130. void cache_push (unsigned long paddr, int len)
  131. {
  132. if (CPU_IS_COLDFIRE) {
  133. flush_cf_bcache(0, DCACHE_MAX_ADDR);
  134. } else if (CPU_IS_040_OR_060) {
  135. int tmp = PAGE_SIZE;
  136. /*
  137. * on 68040 or 68060, push cache lines for pages in the range;
  138. * on the '040 this also invalidates the pushed lines, but not on
  139. * the '060!
  140. */
  141. len += paddr & (PAGE_SIZE - 1);
  142. /*
  143. * Work around bug I17 in the 68060 affecting some instruction
  144. * lines not being invalidated properly.
  145. */
  146. paddr &= PAGE_MASK;
  147. do {
  148. push040(paddr);
  149. paddr += tmp;
  150. } while ((len -= tmp) > 0);
  151. }
  152. /*
  153. * 68030/68020 have no writeback cache. On the other hand,
  154. * cache_push is actually a superset of cache_clear (the lines
  155. * get written back and invalidated), so we should make sure
  156. * to perform the corresponding actions. After all, this is getting
  157. * called in places where we've just loaded code, or whatever, so
  158. * flushing the icache is appropriate; flushing the dcache shouldn't
  159. * be required.
  160. */
  161. else /* 68030 or 68020 */
  162. asm volatile ("movec %/cacr,%/d0\n\t"
  163. "oriw %0,%/d0\n\t"
  164. "movec %/d0,%/cacr"
  165. : : "i" (FLUSH_I)
  166. : "d0");
  167. #ifdef CONFIG_M68K_L2_CACHE
  168. if(mach_l2_flush)
  169. mach_l2_flush(1);
  170. #endif
  171. }
  172. EXPORT_SYMBOL(cache_push);