cacheflush.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /* Caches are physically-indexed and so don't need special treatment */
  22. #define flush_cache_all() do { } while (0)
  23. #define flush_cache_mm(mm) do { } while (0)
  24. #define flush_cache_dup_mm(mm) do { } while (0)
  25. #define flush_cache_range(vma, start, end) do { } while (0)
  26. #define flush_cache_page(vma, vmaddr, pfn) do { } while (0)
  27. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
  28. #define flush_dcache_page(page) do { } while (0)
  29. #define flush_dcache_mmap_lock(mapping) do { } while (0)
  30. #define flush_dcache_mmap_unlock(mapping) do { } while (0)
  31. #define flush_cache_vmap(start, end) do { } while (0)
  32. #define flush_cache_vunmap(start, end) do { } while (0)
  33. #define flush_icache_page(vma, pg) do { } while (0)
  34. #define flush_icache_user_range(vma, pg, adr, len) do { } while (0)
  35. /* See "arch/tile/lib/__invalidate_icache.S". */
  36. extern void __invalidate_icache(unsigned long start, unsigned long size);
  37. /* Flush the icache just on this cpu */
  38. static inline void __flush_icache_range(unsigned long start, unsigned long end)
  39. {
  40. __invalidate_icache(start, end - start);
  41. }
  42. /* Flush the entire icache on this cpu. */
  43. #define __flush_icache() __flush_icache_range(0, CHIP_L1I_CACHE_SIZE())
  44. #ifdef CONFIG_SMP
  45. /*
  46. * When the kernel writes to its own text we need to do an SMP
  47. * broadcast to make the L1I coherent everywhere. This includes
  48. * module load and single step.
  49. */
  50. extern void flush_icache_range(unsigned long start, unsigned long end);
  51. #else
  52. #define flush_icache_range __flush_icache_range
  53. #endif
  54. /*
  55. * An update to an executable user page requires icache flushing.
  56. * We could carefully update only tiles that are running this process,
  57. * and rely on the fact that we flush the icache on every context
  58. * switch to avoid doing extra work here. But for now, I'll be
  59. * conservative and just do a global icache flush.
  60. */
  61. static inline void copy_to_user_page(struct vm_area_struct *vma,
  62. struct page *page, unsigned long vaddr,
  63. void *dst, void *src, int len)
  64. {
  65. memcpy(dst, src, len);
  66. if (vma->vm_flags & VM_EXEC) {
  67. flush_icache_range((unsigned long) dst,
  68. (unsigned long) dst + len);
  69. }
  70. }
  71. #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
  72. memcpy((dst), (src), (len))
  73. /*
  74. * Invalidate a VA range; pads to L2 cacheline boundaries.
  75. *
  76. * Note that on TILE64, __inv_buffer() actually flushes modified
  77. * cache lines in addition to invalidating them, i.e., it's the
  78. * same as __finv_buffer().
  79. */
  80. static inline void __inv_buffer(void *buffer, size_t size)
  81. {
  82. char *next = (char *)((long)buffer & -L2_CACHE_BYTES);
  83. char *finish = (char *)L2_CACHE_ALIGN((long)buffer + size);
  84. while (next < finish) {
  85. __insn_inv(next);
  86. next += CHIP_INV_STRIDE();
  87. }
  88. }
  89. /* Flush a VA range; pads to L2 cacheline boundaries. */
  90. static inline void __flush_buffer(void *buffer, size_t size)
  91. {
  92. char *next = (char *)((long)buffer & -L2_CACHE_BYTES);
  93. char *finish = (char *)L2_CACHE_ALIGN((long)buffer + size);
  94. while (next < finish) {
  95. __insn_flush(next);
  96. next += CHIP_FLUSH_STRIDE();
  97. }
  98. }
  99. /* Flush & invalidate a VA range; pads to L2 cacheline boundaries. */
  100. static inline void __finv_buffer(void *buffer, size_t size)
  101. {
  102. char *next = (char *)((long)buffer & -L2_CACHE_BYTES);
  103. char *finish = (char *)L2_CACHE_ALIGN((long)buffer + size);
  104. while (next < finish) {
  105. __insn_finv(next);
  106. next += CHIP_FINV_STRIDE();
  107. }
  108. }
  109. /* Invalidate a VA range, then memory fence. */
  110. static inline void inv_buffer(void *buffer, size_t size)
  111. {
  112. __inv_buffer(buffer, size);
  113. mb_incoherent();
  114. }
  115. /* Flush a VA range, then memory fence. */
  116. static inline void flush_buffer(void *buffer, size_t size)
  117. {
  118. __flush_buffer(buffer, size);
  119. mb_incoherent();
  120. }
  121. /* Flush & invalidate a VA range, then memory fence. */
  122. static inline void finv_buffer(void *buffer, size_t size)
  123. {
  124. __finv_buffer(buffer, size);
  125. mb_incoherent();
  126. }
  127. #endif /* _ASM_TILE_CACHEFLUSH_H */