cacheflush.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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/kgdb.h>
  22. #include <linux/mm.h>
  23. /*
  24. * This flag is used to indicate that the page pointed to by a pte is clean
  25. * and does not require cleaning before returning it to the user.
  26. */
  27. #define PG_dcache_clean PG_arch_1
  28. /*
  29. * MM Cache Management
  30. * ===================
  31. *
  32. * The arch/arm64/mm/cache.S implements these methods.
  33. *
  34. * Start addresses are inclusive and end addresses are exclusive; start
  35. * addresses should be rounded down, end addresses up.
  36. *
  37. * See Documentation/core-api/cachetlb.rst for more information. Please note that
  38. * the implementation assumes non-aliasing VIPT D-cache and (aliasing)
  39. * VIPT I-cache.
  40. *
  41. * flush_cache_mm(mm)
  42. *
  43. * Clean and invalidate all user space cache entries
  44. * before a change of page tables.
  45. *
  46. * flush_icache_range(start, end)
  47. *
  48. * Ensure coherency between the I-cache and the D-cache in the
  49. * region described by start, end.
  50. * - start - virtual start address
  51. * - end - virtual end address
  52. *
  53. * invalidate_icache_range(start, end)
  54. *
  55. * Invalidate the I-cache in the region described by start, end.
  56. * - start - virtual start address
  57. * - end - virtual end address
  58. *
  59. * __flush_cache_user_range(start, end)
  60. *
  61. * Ensure coherency between the I-cache and the D-cache in the
  62. * region described by start, end.
  63. * - start - virtual start address
  64. * - end - virtual end address
  65. *
  66. * __flush_dcache_area(kaddr, size)
  67. *
  68. * Ensure that the data held in page is written back.
  69. * - kaddr - page address
  70. * - size - region size
  71. */
  72. extern void __flush_icache_range(unsigned long start, unsigned long end);
  73. extern int invalidate_icache_range(unsigned long start, unsigned long end);
  74. extern void __flush_dcache_area(void *addr, size_t len);
  75. extern void __inval_dcache_area(void *addr, size_t len);
  76. extern void __clean_dcache_area_poc(void *addr, size_t len);
  77. extern void __clean_dcache_area_pop(void *addr, size_t len);
  78. extern void __clean_dcache_area_pou(void *addr, size_t len);
  79. extern long __flush_cache_user_range(unsigned long start, unsigned long end);
  80. extern void sync_icache_aliases(void *kaddr, unsigned long len);
  81. static inline void flush_icache_range(unsigned long start, unsigned long end)
  82. {
  83. __flush_icache_range(start, end);
  84. /*
  85. * IPI all online CPUs so that they undergo a context synchronization
  86. * event and are forced to refetch the new instructions.
  87. */
  88. /*
  89. * KGDB performs cache maintenance with interrupts disabled, so we
  90. * will deadlock trying to IPI the secondary CPUs. In theory, we can
  91. * set CACHE_FLUSH_IS_SAFE to 0 to avoid this known issue, but that
  92. * just means that KGDB will elide the maintenance altogether! As it
  93. * turns out, KGDB uses IPIs to round-up the secondary CPUs during
  94. * the patching operation, so we don't need extra IPIs here anyway.
  95. * In which case, add a KGDB-specific bodge and return early.
  96. */
  97. if (in_dbg_master())
  98. return;
  99. kick_all_cpus_sync();
  100. }
  101. static inline void flush_cache_mm(struct mm_struct *mm)
  102. {
  103. }
  104. static inline void flush_cache_page(struct vm_area_struct *vma,
  105. unsigned long user_addr, unsigned long pfn)
  106. {
  107. }
  108. static inline void flush_cache_range(struct vm_area_struct *vma,
  109. unsigned long start, unsigned long end)
  110. {
  111. }
  112. /*
  113. * Cache maintenance functions used by the DMA API. No to be used directly.
  114. */
  115. extern void __dma_map_area(const void *, size_t, int);
  116. extern void __dma_unmap_area(const void *, size_t, int);
  117. extern void __dma_flush_area(const void *, size_t);
  118. /*
  119. * Copy user data from/to a page which is mapped into a different
  120. * processes address space. Really, we want to allow our "user
  121. * space" model to handle this.
  122. */
  123. extern void copy_to_user_page(struct vm_area_struct *, struct page *,
  124. unsigned long, void *, const void *, unsigned long);
  125. #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
  126. do { \
  127. memcpy(dst, src, len); \
  128. } while (0)
  129. #define flush_cache_dup_mm(mm) flush_cache_mm(mm)
  130. /*
  131. * flush_dcache_page is used when the kernel has written to the page
  132. * cache page at virtual address page->virtual.
  133. *
  134. * If this page isn't mapped (ie, page_mapping == NULL), or it might
  135. * have userspace mappings, then we _must_ always clean + invalidate
  136. * the dcache entries associated with the kernel mapping.
  137. *
  138. * Otherwise we can defer the operation, and clean the cache when we are
  139. * about to change to user space. This is the same method as used on SPARC64.
  140. * See update_mmu_cache for the user space part.
  141. */
  142. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
  143. extern void flush_dcache_page(struct page *);
  144. static inline void __flush_icache_all(void)
  145. {
  146. if (cpus_have_const_cap(ARM64_HAS_CACHE_DIC))
  147. return;
  148. asm("ic ialluis");
  149. dsb(ish);
  150. }
  151. #define flush_dcache_mmap_lock(mapping) do { } while (0)
  152. #define flush_dcache_mmap_unlock(mapping) do { } while (0)
  153. /*
  154. * We don't appear to need to do anything here. In fact, if we did, we'd
  155. * duplicate cache flushing elsewhere performed by flush_dcache_page().
  156. */
  157. #define flush_icache_page(vma,page) do { } while (0)
  158. /*
  159. * Not required on AArch64 (PIPT or VIPT non-aliasing D-cache).
  160. */
  161. static inline void flush_cache_vmap(unsigned long start, unsigned long end)
  162. {
  163. }
  164. static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
  165. {
  166. }
  167. int set_memory_valid(unsigned long addr, int numpages, int enable);
  168. #endif