cacheflush_mm.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #ifndef _M68K_CACHEFLUSH_H
  2. #define _M68K_CACHEFLUSH_H
  3. #include <linux/mm.h>
  4. #ifdef CONFIG_COLDFIRE
  5. #include <asm/mcfsim.h>
  6. #endif
  7. /* cache code */
  8. #define FLUSH_I_AND_D (0x00000808)
  9. #define FLUSH_I (0x00000008)
  10. #ifndef ICACHE_MAX_ADDR
  11. #define ICACHE_MAX_ADDR 0
  12. #define ICACHE_SET_MASK 0
  13. #define DCACHE_MAX_ADDR 0
  14. #define DCACHE_SETMASK 0
  15. #endif
  16. static inline void flush_cf_icache(unsigned long start, unsigned long end)
  17. {
  18. unsigned long set;
  19. for (set = start; set <= end; set += (0x10 - 3)) {
  20. __asm__ __volatile__ (
  21. "cpushl %%ic,(%0)\n\t"
  22. "addq%.l #1,%0\n\t"
  23. "cpushl %%ic,(%0)\n\t"
  24. "addq%.l #1,%0\n\t"
  25. "cpushl %%ic,(%0)\n\t"
  26. "addq%.l #1,%0\n\t"
  27. "cpushl %%ic,(%0)"
  28. : "=a" (set)
  29. : "a" (set));
  30. }
  31. }
  32. static inline void flush_cf_dcache(unsigned long start, unsigned long end)
  33. {
  34. unsigned long set;
  35. for (set = start; set <= end; set += (0x10 - 3)) {
  36. __asm__ __volatile__ (
  37. "cpushl %%dc,(%0)\n\t"
  38. "addq%.l #1,%0\n\t"
  39. "cpushl %%dc,(%0)\n\t"
  40. "addq%.l #1,%0\n\t"
  41. "cpushl %%dc,(%0)\n\t"
  42. "addq%.l #1,%0\n\t"
  43. "cpushl %%dc,(%0)"
  44. : "=a" (set)
  45. : "a" (set));
  46. }
  47. }
  48. static inline void flush_cf_bcache(unsigned long start, unsigned long end)
  49. {
  50. unsigned long set;
  51. for (set = start; set <= end; set += (0x10 - 3)) {
  52. __asm__ __volatile__ (
  53. "cpushl %%bc,(%0)\n\t"
  54. "addq%.l #1,%0\n\t"
  55. "cpushl %%bc,(%0)\n\t"
  56. "addq%.l #1,%0\n\t"
  57. "cpushl %%bc,(%0)\n\t"
  58. "addq%.l #1,%0\n\t"
  59. "cpushl %%bc,(%0)"
  60. : "=a" (set)
  61. : "a" (set));
  62. }
  63. }
  64. /*
  65. * Cache handling functions
  66. */
  67. static inline void flush_icache(void)
  68. {
  69. if (CPU_IS_COLDFIRE) {
  70. flush_cf_icache(0, ICACHE_MAX_ADDR);
  71. } else if (CPU_IS_040_OR_060) {
  72. asm volatile ( "nop\n"
  73. " .chip 68040\n"
  74. " cpusha %bc\n"
  75. " .chip 68k");
  76. } else {
  77. unsigned long tmp;
  78. asm volatile ( "movec %%cacr,%0\n"
  79. " or.w %1,%0\n"
  80. " movec %0,%%cacr"
  81. : "=&d" (tmp)
  82. : "id" (FLUSH_I));
  83. }
  84. }
  85. /*
  86. * invalidate the cache for the specified memory range.
  87. * It starts at the physical address specified for
  88. * the given number of bytes.
  89. */
  90. extern void cache_clear(unsigned long paddr, int len);
  91. /*
  92. * push any dirty cache in the specified memory range.
  93. * It starts at the physical address specified for
  94. * the given number of bytes.
  95. */
  96. extern void cache_push(unsigned long paddr, int len);
  97. /*
  98. * push and invalidate pages in the specified user virtual
  99. * memory range.
  100. */
  101. extern void cache_push_v(unsigned long vaddr, int len);
  102. /* This is needed whenever the virtual mapping of the current
  103. process changes. */
  104. #define __flush_cache_all() \
  105. ({ \
  106. if (CPU_IS_COLDFIRE) { \
  107. flush_cf_dcache(0, DCACHE_MAX_ADDR); \
  108. } else if (CPU_IS_040_OR_060) { \
  109. __asm__ __volatile__("nop\n\t" \
  110. ".chip 68040\n\t" \
  111. "cpusha %dc\n\t" \
  112. ".chip 68k"); \
  113. } else { \
  114. unsigned long _tmp; \
  115. __asm__ __volatile__("movec %%cacr,%0\n\t" \
  116. "orw %1,%0\n\t" \
  117. "movec %0,%%cacr" \
  118. : "=&d" (_tmp) \
  119. : "di" (FLUSH_I_AND_D)); \
  120. } \
  121. })
  122. #define __flush_cache_030() \
  123. ({ \
  124. if (CPU_IS_020_OR_030) { \
  125. unsigned long _tmp; \
  126. __asm__ __volatile__("movec %%cacr,%0\n\t" \
  127. "orw %1,%0\n\t" \
  128. "movec %0,%%cacr" \
  129. : "=&d" (_tmp) \
  130. : "di" (FLUSH_I_AND_D)); \
  131. } \
  132. })
  133. #define flush_cache_all() __flush_cache_all()
  134. #define flush_cache_vmap(start, end) flush_cache_all()
  135. #define flush_cache_vunmap(start, end) flush_cache_all()
  136. static inline void flush_cache_mm(struct mm_struct *mm)
  137. {
  138. if (mm == current->mm)
  139. __flush_cache_030();
  140. }
  141. #define flush_cache_dup_mm(mm) flush_cache_mm(mm)
  142. /* flush_cache_range/flush_cache_page must be macros to avoid
  143. a dependency on linux/mm.h, which includes this file... */
  144. static inline void flush_cache_range(struct vm_area_struct *vma,
  145. unsigned long start,
  146. unsigned long end)
  147. {
  148. if (vma->vm_mm == current->mm)
  149. __flush_cache_030();
  150. }
  151. static inline void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn)
  152. {
  153. if (vma->vm_mm == current->mm)
  154. __flush_cache_030();
  155. }
  156. /* Push the page at kernel virtual address and clear the icache */
  157. /* RZ: use cpush %bc instead of cpush %dc, cinv %ic */
  158. static inline void __flush_page_to_ram(void *vaddr)
  159. {
  160. if (CPU_IS_COLDFIRE) {
  161. unsigned long addr, start, end;
  162. addr = ((unsigned long) vaddr) & ~(PAGE_SIZE - 1);
  163. start = addr & ICACHE_SET_MASK;
  164. end = (addr + PAGE_SIZE - 1) & ICACHE_SET_MASK;
  165. if (start > end) {
  166. flush_cf_bcache(0, end);
  167. end = ICACHE_MAX_ADDR;
  168. }
  169. flush_cf_bcache(start, end);
  170. } else if (CPU_IS_040_OR_060) {
  171. __asm__ __volatile__("nop\n\t"
  172. ".chip 68040\n\t"
  173. "cpushp %%bc,(%0)\n\t"
  174. ".chip 68k"
  175. : : "a" (__pa(vaddr)));
  176. } else {
  177. unsigned long _tmp;
  178. __asm__ __volatile__("movec %%cacr,%0\n\t"
  179. "orw %1,%0\n\t"
  180. "movec %0,%%cacr"
  181. : "=&d" (_tmp)
  182. : "di" (FLUSH_I));
  183. }
  184. }
  185. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
  186. #define flush_dcache_page(page) __flush_page_to_ram(page_address(page))
  187. #define flush_dcache_mmap_lock(mapping) do { } while (0)
  188. #define flush_dcache_mmap_unlock(mapping) do { } while (0)
  189. #define flush_icache_page(vma, page) __flush_page_to_ram(page_address(page))
  190. extern void flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
  191. unsigned long addr, int len);
  192. extern void flush_icache_range(unsigned long address, unsigned long endaddr);
  193. static inline void copy_to_user_page(struct vm_area_struct *vma,
  194. struct page *page, unsigned long vaddr,
  195. void *dst, void *src, int len)
  196. {
  197. flush_cache_page(vma, vaddr, page_to_pfn(page));
  198. memcpy(dst, src, len);
  199. flush_icache_user_range(vma, page, vaddr, len);
  200. }
  201. static inline void copy_from_user_page(struct vm_area_struct *vma,
  202. struct page *page, unsigned long vaddr,
  203. void *dst, void *src, int len)
  204. {
  205. flush_cache_page(vma, vaddr, page_to_pfn(page));
  206. memcpy(dst, src, len);
  207. }
  208. #endif /* _M68K_CACHEFLUSH_H */