cacheflush.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Based on arch/arm/include/asm/cacheflush.h
  3. *
  4. * Copyright (C) 1999-2002 Russell King.
  5. * Copyright (C) 2012 ARM Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __ASM_CACHEFLUSH_H
  20. #define __ASM_CACHEFLUSH_H
  21. #include <linux/mm.h>
  22. /*
  23. * This flag is used to indicate that the page pointed to by a pte is clean
  24. * and does not require cleaning before returning it to the user.
  25. */
  26. #define PG_dcache_clean PG_arch_1
  27. /*
  28. * MM Cache Management
  29. * ===================
  30. *
  31. * The arch/arm64/mm/cache.S implements these methods.
  32. *
  33. * Start addresses are inclusive and end addresses are exclusive; start
  34. * addresses should be rounded down, end addresses up.
  35. *
  36. * See Documentation/cachetlb.txt for more information. Please note that
  37. * the implementation assumes non-aliasing VIPT D-cache and (aliasing)
  38. * VIPT or ASID-tagged VIVT I-cache.
  39. *
  40. * flush_cache_all()
  41. *
  42. * Unconditionally clean and invalidate the entire cache.
  43. *
  44. * flush_cache_mm(mm)
  45. *
  46. * Clean and invalidate all user space cache entries
  47. * before a change of page tables.
  48. *
  49. * flush_icache_range(start, end)
  50. *
  51. * Ensure coherency between the I-cache and the D-cache in the
  52. * region described by start, end.
  53. * - start - virtual start address
  54. * - end - virtual end address
  55. *
  56. * __flush_cache_user_range(start, end)
  57. *
  58. * Ensure coherency between the I-cache and the D-cache in the
  59. * region described by start, end.
  60. * - start - virtual start address
  61. * - end - virtual end address
  62. *
  63. * __flush_dcache_area(kaddr, size)
  64. *
  65. * Ensure that the data held in page is written back.
  66. * - kaddr - page address
  67. * - size - region size
  68. */
  69. extern void flush_cache_all(void);
  70. extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
  71. extern void flush_icache_range(unsigned long start, unsigned long end);
  72. extern void __flush_dcache_area(void *addr, size_t len);
  73. extern void __flush_cache_user_range(unsigned long start, unsigned long end);
  74. static inline void flush_cache_mm(struct mm_struct *mm)
  75. {
  76. }
  77. static inline void flush_cache_page(struct vm_area_struct *vma,
  78. unsigned long user_addr, unsigned long pfn)
  79. {
  80. }
  81. /*
  82. * Copy user data from/to a page which is mapped into a different
  83. * processes address space. Really, we want to allow our "user
  84. * space" model to handle this.
  85. */
  86. extern void copy_to_user_page(struct vm_area_struct *, struct page *,
  87. unsigned long, void *, const void *, unsigned long);
  88. #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
  89. do { \
  90. memcpy(dst, src, len); \
  91. } while (0)
  92. #define flush_cache_dup_mm(mm) flush_cache_mm(mm)
  93. /*
  94. * flush_dcache_page is used when the kernel has written to the page
  95. * cache page at virtual address page->virtual.
  96. *
  97. * If this page isn't mapped (ie, page_mapping == NULL), or it might
  98. * have userspace mappings, then we _must_ always clean + invalidate
  99. * the dcache entries associated with the kernel mapping.
  100. *
  101. * Otherwise we can defer the operation, and clean the cache when we are
  102. * about to change to user space. This is the same method as used on SPARC64.
  103. * See update_mmu_cache for the user space part.
  104. */
  105. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
  106. extern void flush_dcache_page(struct page *);
  107. static inline void __flush_icache_all(void)
  108. {
  109. asm("ic ialluis");
  110. }
  111. #define flush_dcache_mmap_lock(mapping) \
  112. spin_lock_irq(&(mapping)->tree_lock)
  113. #define flush_dcache_mmap_unlock(mapping) \
  114. spin_unlock_irq(&(mapping)->tree_lock)
  115. #define flush_icache_user_range(vma,page,addr,len) \
  116. flush_dcache_page(page)
  117. /*
  118. * We don't appear to need to do anything here. In fact, if we did, we'd
  119. * duplicate cache flushing elsewhere performed by flush_dcache_page().
  120. */
  121. #define flush_icache_page(vma,page) do { } while (0)
  122. /*
  123. * flush_cache_vmap() is used when creating mappings (eg, via vmap,
  124. * vmalloc, ioremap etc) in kernel space for pages. On non-VIPT
  125. * caches, since the direct-mappings of these pages may contain cached
  126. * data, we need to do a full cache flush to ensure that writebacks
  127. * don't corrupt data placed into these pages via the new mappings.
  128. */
  129. static inline void flush_cache_vmap(unsigned long start, unsigned long end)
  130. {
  131. /*
  132. * set_pte_at() called from vmap_pte_range() does not
  133. * have a DSB after cleaning the cache line.
  134. */
  135. dsb();
  136. }
  137. static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
  138. {
  139. }
  140. #endif