cacheflush_mm.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #ifndef _M68K_CACHEFLUSH_H
  2. #define _M68K_CACHEFLUSH_H
  3. #include <linux/mm.h>
  4. /* cache code */
  5. #define FLUSH_I_AND_D (0x00000808)
  6. #define FLUSH_I (0x00000008)
  7. /*
  8. * Cache handling functions
  9. */
  10. static inline void flush_icache(void)
  11. {
  12. if (CPU_IS_040_OR_060)
  13. asm volatile ( "nop\n"
  14. " .chip 68040\n"
  15. " cpusha %bc\n"
  16. " .chip 68k");
  17. else {
  18. unsigned long tmp;
  19. asm volatile ( "movec %%cacr,%0\n"
  20. " or.w %1,%0\n"
  21. " movec %0,%%cacr"
  22. : "=&d" (tmp)
  23. : "id" (FLUSH_I));
  24. }
  25. }
  26. /*
  27. * invalidate the cache for the specified memory range.
  28. * It starts at the physical address specified for
  29. * the given number of bytes.
  30. */
  31. extern void cache_clear(unsigned long paddr, int len);
  32. /*
  33. * push any dirty cache in the specified memory range.
  34. * It starts at the physical address specified for
  35. * the given number of bytes.
  36. */
  37. extern void cache_push(unsigned long paddr, int len);
  38. /*
  39. * push and invalidate pages in the specified user virtual
  40. * memory range.
  41. */
  42. extern void cache_push_v(unsigned long vaddr, int len);
  43. /* This is needed whenever the virtual mapping of the current
  44. process changes. */
  45. #define __flush_cache_all() \
  46. ({ \
  47. if (CPU_IS_040_OR_060) \
  48. __asm__ __volatile__("nop\n\t" \
  49. ".chip 68040\n\t" \
  50. "cpusha %dc\n\t" \
  51. ".chip 68k"); \
  52. else { \
  53. unsigned long _tmp; \
  54. __asm__ __volatile__("movec %%cacr,%0\n\t" \
  55. "orw %1,%0\n\t" \
  56. "movec %0,%%cacr" \
  57. : "=&d" (_tmp) \
  58. : "di" (FLUSH_I_AND_D)); \
  59. } \
  60. })
  61. #define __flush_cache_030() \
  62. ({ \
  63. if (CPU_IS_020_OR_030) { \
  64. unsigned long _tmp; \
  65. __asm__ __volatile__("movec %%cacr,%0\n\t" \
  66. "orw %1,%0\n\t" \
  67. "movec %0,%%cacr" \
  68. : "=&d" (_tmp) \
  69. : "di" (FLUSH_I_AND_D)); \
  70. } \
  71. })
  72. #define flush_cache_all() __flush_cache_all()
  73. #define flush_cache_vmap(start, end) flush_cache_all()
  74. #define flush_cache_vunmap(start, end) flush_cache_all()
  75. static inline void flush_cache_mm(struct mm_struct *mm)
  76. {
  77. if (mm == current->mm)
  78. __flush_cache_030();
  79. }
  80. #define flush_cache_dup_mm(mm) flush_cache_mm(mm)
  81. /* flush_cache_range/flush_cache_page must be macros to avoid
  82. a dependency on linux/mm.h, which includes this file... */
  83. static inline void flush_cache_range(struct vm_area_struct *vma,
  84. unsigned long start,
  85. unsigned long end)
  86. {
  87. if (vma->vm_mm == current->mm)
  88. __flush_cache_030();
  89. }
  90. static inline void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn)
  91. {
  92. if (vma->vm_mm == current->mm)
  93. __flush_cache_030();
  94. }
  95. /* Push the page at kernel virtual address and clear the icache */
  96. /* RZ: use cpush %bc instead of cpush %dc, cinv %ic */
  97. static inline void __flush_page_to_ram(void *vaddr)
  98. {
  99. if (CPU_IS_040_OR_060) {
  100. __asm__ __volatile__("nop\n\t"
  101. ".chip 68040\n\t"
  102. "cpushp %%bc,(%0)\n\t"
  103. ".chip 68k"
  104. : : "a" (__pa(vaddr)));
  105. } else {
  106. unsigned long _tmp;
  107. __asm__ __volatile__("movec %%cacr,%0\n\t"
  108. "orw %1,%0\n\t"
  109. "movec %0,%%cacr"
  110. : "=&d" (_tmp)
  111. : "di" (FLUSH_I));
  112. }
  113. }
  114. #define flush_dcache_page(page) __flush_page_to_ram(page_address(page))
  115. #define flush_dcache_mmap_lock(mapping) do { } while (0)
  116. #define flush_dcache_mmap_unlock(mapping) do { } while (0)
  117. #define flush_icache_page(vma, page) __flush_page_to_ram(page_address(page))
  118. extern void flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
  119. unsigned long addr, int len);
  120. extern void flush_icache_range(unsigned long address, unsigned long endaddr);
  121. static inline void copy_to_user_page(struct vm_area_struct *vma,
  122. struct page *page, unsigned long vaddr,
  123. void *dst, void *src, int len)
  124. {
  125. flush_cache_page(vma, vaddr, page_to_pfn(page));
  126. memcpy(dst, src, len);
  127. flush_icache_user_range(vma, page, vaddr, len);
  128. }
  129. static inline void copy_from_user_page(struct vm_area_struct *vma,
  130. struct page *page, unsigned long vaddr,
  131. void *dst, void *src, int len)
  132. {
  133. flush_cache_page(vma, vaddr, page_to_pfn(page));
  134. memcpy(dst, src, len);
  135. }
  136. #endif /* _M68K_CACHEFLUSH_H */