cacheflush.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef _M68K_CACHEFLUSH_H
  2. #define _M68K_CACHEFLUSH_H
  3. #include <linux/mm.h>
  4. /*
  5. * Cache handling functions
  6. */
  7. #define flush_icache() \
  8. ({ \
  9. if (CPU_IS_040_OR_060) \
  10. __asm__ __volatile__("nop\n\t" \
  11. ".chip 68040\n\t" \
  12. "cinva %%ic\n\t" \
  13. ".chip 68k" : ); \
  14. else { \
  15. unsigned long _tmp; \
  16. __asm__ __volatile__("movec %%cacr,%0\n\t" \
  17. "orw %1,%0\n\t" \
  18. "movec %0,%%cacr" \
  19. : "=&d" (_tmp) \
  20. : "id" (FLUSH_I)); \
  21. } \
  22. })
  23. /*
  24. * invalidate the cache for the specified memory range.
  25. * It starts at the physical address specified for
  26. * the given number of bytes.
  27. */
  28. extern void cache_clear(unsigned long paddr, int len);
  29. /*
  30. * push any dirty cache in the specified memory range.
  31. * It starts at the physical address specified for
  32. * the given number of bytes.
  33. */
  34. extern void cache_push(unsigned long paddr, int len);
  35. /*
  36. * push and invalidate pages in the specified user virtual
  37. * memory range.
  38. */
  39. extern void cache_push_v(unsigned long vaddr, int len);
  40. /* cache code */
  41. #define FLUSH_I_AND_D (0x00000808)
  42. #define FLUSH_I (0x00000008)
  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. /* flush_cache_range/flush_cache_page must be macros to avoid
  81. a dependency on linux/mm.h, which includes this file... */
  82. static inline void flush_cache_range(struct vm_area_struct *vma,
  83. unsigned long start,
  84. unsigned long end)
  85. {
  86. if (vma->vm_mm == current->mm)
  87. __flush_cache_030();
  88. }
  89. static inline void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn)
  90. {
  91. if (vma->vm_mm == current->mm)
  92. __flush_cache_030();
  93. }
  94. /* Push the page at kernel virtual address and clear the icache */
  95. /* RZ: use cpush %bc instead of cpush %dc, cinv %ic */
  96. static inline void __flush_page_to_ram(void *vaddr)
  97. {
  98. if (CPU_IS_040_OR_060) {
  99. __asm__ __volatile__("nop\n\t"
  100. ".chip 68040\n\t"
  101. "cpushp %%bc,(%0)\n\t"
  102. ".chip 68k"
  103. : : "a" (__pa(vaddr)));
  104. } else {
  105. unsigned long _tmp;
  106. __asm__ __volatile__("movec %%cacr,%0\n\t"
  107. "orw %1,%0\n\t"
  108. "movec %0,%%cacr"
  109. : "=&d" (_tmp)
  110. : "di" (FLUSH_I));
  111. }
  112. }
  113. #define flush_dcache_page(page) __flush_page_to_ram(page_address(page))
  114. #define flush_dcache_mmap_lock(mapping) do { } while (0)
  115. #define flush_dcache_mmap_unlock(mapping) do { } while (0)
  116. #define flush_icache_page(vma, page) __flush_page_to_ram(page_address(page))
  117. extern void flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
  118. unsigned long addr, int len);
  119. extern void flush_icache_range(unsigned long address, unsigned long endaddr);
  120. static inline void copy_to_user_page(struct vm_area_struct *vma,
  121. struct page *page, unsigned long vaddr,
  122. void *dst, void *src, int len)
  123. {
  124. flush_cache_page(vma, vaddr, page_to_pfn(page));
  125. memcpy(dst, src, len);
  126. flush_icache_user_range(vma, page, vaddr, len);
  127. }
  128. static inline void copy_from_user_page(struct vm_area_struct *vma,
  129. struct page *page, unsigned long vaddr,
  130. void *dst, void *src, int len)
  131. {
  132. flush_cache_page(vma, vaddr, page_to_pfn(page));
  133. memcpy(dst, src, len);
  134. }
  135. #endif /* _M68K_CACHEFLUSH_H */