cacheflush.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _ASM_TILE_CACHEFLUSH_H
  15. #define _ASM_TILE_CACHEFLUSH_H
  16. #include <arch/chip.h>
  17. /* Keep includes the same across arches. */
  18. #include <linux/mm.h>
  19. #include <linux/cache.h>
  20. #include <asm/system.h>
  21. #include <arch/icache.h>
  22. /* Caches are physically-indexed and so don't need special treatment */
  23. #define flush_cache_all() do { } while (0)
  24. #define flush_cache_mm(mm) do { } while (0)
  25. #define flush_cache_dup_mm(mm) do { } while (0)
  26. #define flush_cache_range(vma, start, end) do { } while (0)
  27. #define flush_cache_page(vma, vmaddr, pfn) do { } while (0)
  28. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
  29. #define flush_dcache_page(page) do { } while (0)
  30. #define flush_dcache_mmap_lock(mapping) do { } while (0)
  31. #define flush_dcache_mmap_unlock(mapping) do { } while (0)
  32. #define flush_cache_vmap(start, end) do { } while (0)
  33. #define flush_cache_vunmap(start, end) do { } while (0)
  34. #define flush_icache_page(vma, pg) do { } while (0)
  35. #define flush_icache_user_range(vma, pg, adr, len) do { } while (0)
  36. /* Flush the icache just on this cpu */
  37. extern void __flush_icache_range(unsigned long start, unsigned long end);
  38. /* Flush the entire icache on this cpu. */
  39. #define __flush_icache() __flush_icache_range(0, CHIP_L1I_CACHE_SIZE())
  40. #ifdef CONFIG_SMP
  41. /*
  42. * When the kernel writes to its own text we need to do an SMP
  43. * broadcast to make the L1I coherent everywhere. This includes
  44. * module load and single step.
  45. */
  46. extern void flush_icache_range(unsigned long start, unsigned long end);
  47. #else
  48. #define flush_icache_range __flush_icache_range
  49. #endif
  50. /*
  51. * An update to an executable user page requires icache flushing.
  52. * We could carefully update only tiles that are running this process,
  53. * and rely on the fact that we flush the icache on every context
  54. * switch to avoid doing extra work here. But for now, I'll be
  55. * conservative and just do a global icache flush.
  56. */
  57. static inline void copy_to_user_page(struct vm_area_struct *vma,
  58. struct page *page, unsigned long vaddr,
  59. void *dst, void *src, int len)
  60. {
  61. memcpy(dst, src, len);
  62. if (vma->vm_flags & VM_EXEC) {
  63. flush_icache_range((unsigned long) dst,
  64. (unsigned long) dst + len);
  65. }
  66. }
  67. #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
  68. memcpy((dst), (src), (len))
  69. /*
  70. * Invalidate a VA range; pads to L2 cacheline boundaries.
  71. *
  72. * Note that on TILE64, __inv_buffer() actually flushes modified
  73. * cache lines in addition to invalidating them, i.e., it's the
  74. * same as __finv_buffer().
  75. */
  76. static inline void __inv_buffer(void *buffer, size_t size)
  77. {
  78. char *next = (char *)((long)buffer & -L2_CACHE_BYTES);
  79. char *finish = (char *)L2_CACHE_ALIGN((long)buffer + size);
  80. while (next < finish) {
  81. __insn_inv(next);
  82. next += CHIP_INV_STRIDE();
  83. }
  84. }
  85. /* Flush a VA range; pads to L2 cacheline boundaries. */
  86. static inline void __flush_buffer(void *buffer, size_t size)
  87. {
  88. char *next = (char *)((long)buffer & -L2_CACHE_BYTES);
  89. char *finish = (char *)L2_CACHE_ALIGN((long)buffer + size);
  90. while (next < finish) {
  91. __insn_flush(next);
  92. next += CHIP_FLUSH_STRIDE();
  93. }
  94. }
  95. /* Flush & invalidate a VA range; pads to L2 cacheline boundaries. */
  96. static inline void __finv_buffer(void *buffer, size_t size)
  97. {
  98. char *next = (char *)((long)buffer & -L2_CACHE_BYTES);
  99. char *finish = (char *)L2_CACHE_ALIGN((long)buffer + size);
  100. while (next < finish) {
  101. __insn_finv(next);
  102. next += CHIP_FINV_STRIDE();
  103. }
  104. }
  105. /* Invalidate a VA range and wait for it to be complete. */
  106. static inline void inv_buffer(void *buffer, size_t size)
  107. {
  108. __inv_buffer(buffer, size);
  109. mb();
  110. }
  111. /*
  112. * Flush a locally-homecached VA range and wait for the evicted
  113. * cachelines to hit memory.
  114. */
  115. static inline void flush_buffer_local(void *buffer, size_t size)
  116. {
  117. __flush_buffer(buffer, size);
  118. mb_incoherent();
  119. }
  120. /*
  121. * Flush and invalidate a locally-homecached VA range and wait for the
  122. * evicted cachelines to hit memory.
  123. */
  124. static inline void finv_buffer_local(void *buffer, size_t size)
  125. {
  126. __finv_buffer(buffer, size);
  127. mb_incoherent();
  128. }
  129. /*
  130. * Flush and invalidate a VA range that is homed remotely, waiting
  131. * until the memory controller holds the flushed values. If "hfh" is
  132. * true, we will do a more expensive flush involving additional loads
  133. * to make sure we have touched all the possible home cpus of a buffer
  134. * that is homed with "hash for home".
  135. */
  136. void finv_buffer_remote(void *buffer, size_t size, int hfh);
  137. #endif /* _ASM_TILE_CACHEFLUSH_H */