cacheflush.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * linux/arch/unicore32/include/asm/cacheflush.h
  3. *
  4. * Code specific to PKUnity SoC and UniCore ISA
  5. *
  6. * Copyright (C) 2001-2010 GUAN Xue-tao
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef __UNICORE_CACHEFLUSH_H__
  13. #define __UNICORE_CACHEFLUSH_H__
  14. #include <linux/mm.h>
  15. #include <asm/shmparam.h>
  16. #define CACHE_COLOUR(vaddr) ((vaddr & (SHMLBA - 1)) >> PAGE_SHIFT)
  17. /*
  18. * This flag is used to indicate that the page pointed to by a pte is clean
  19. * and does not require cleaning before returning it to the user.
  20. */
  21. #define PG_dcache_clean PG_arch_1
  22. /*
  23. * MM Cache Management
  24. * ===================
  25. *
  26. * The arch/unicore32/mm/cache.S files implement these methods.
  27. *
  28. * Start addresses are inclusive and end addresses are exclusive;
  29. * start addresses should be rounded down, end addresses up.
  30. *
  31. * See Documentation/core-api/cachetlb.rst for more information.
  32. * Please note that the implementation of these, and the required
  33. * effects are cache-type (VIVT/VIPT/PIPT) specific.
  34. *
  35. * flush_icache_all()
  36. *
  37. * Unconditionally clean and invalidate the entire icache.
  38. * Currently only needed for cache-v6.S and cache-v7.S, see
  39. * __flush_icache_all for the generic implementation.
  40. *
  41. * flush_kern_all()
  42. *
  43. * Unconditionally clean and invalidate the entire cache.
  44. *
  45. * flush_user_all()
  46. *
  47. * Clean and invalidate all user space cache entries
  48. * before a change of page tables.
  49. *
  50. * flush_user_range(start, end, flags)
  51. *
  52. * Clean and invalidate a range of cache entries in the
  53. * specified address space before a change of page tables.
  54. * - start - user start address (inclusive, page aligned)
  55. * - end - user end address (exclusive, page aligned)
  56. * - flags - vma->vm_flags field
  57. *
  58. * coherent_kern_range(start, end)
  59. *
  60. * Ensure coherency between the Icache and the Dcache in the
  61. * region described by start, end. If you have non-snooping
  62. * Harvard caches, you need to implement this function.
  63. * - start - virtual start address
  64. * - end - virtual end address
  65. *
  66. * coherent_user_range(start, end)
  67. *
  68. * Ensure coherency between the Icache and the Dcache in the
  69. * region described by start, end. If you have non-snooping
  70. * Harvard caches, you need to implement this function.
  71. * - start - virtual start address
  72. * - end - virtual end address
  73. *
  74. * flush_kern_dcache_area(kaddr, size)
  75. *
  76. * Ensure that the data held in page is written back.
  77. * - kaddr - page address
  78. * - size - region size
  79. *
  80. * DMA Cache Coherency
  81. * ===================
  82. *
  83. * dma_flush_range(start, end)
  84. *
  85. * Clean and invalidate the specified virtual address range.
  86. * - start - virtual start address
  87. * - end - virtual end address
  88. */
  89. extern void __cpuc_flush_icache_all(void);
  90. extern void __cpuc_flush_kern_all(void);
  91. extern void __cpuc_flush_user_all(void);
  92. extern void __cpuc_flush_user_range(unsigned long, unsigned long, unsigned int);
  93. extern void __cpuc_coherent_kern_range(unsigned long, unsigned long);
  94. extern void __cpuc_coherent_user_range(unsigned long, unsigned long);
  95. extern void __cpuc_flush_dcache_area(void *, size_t);
  96. extern void __cpuc_flush_kern_dcache_area(void *addr, size_t size);
  97. /*
  98. * Copy user data from/to a page which is mapped into a different
  99. * processes address space. Really, we want to allow our "user
  100. * space" model to handle this.
  101. */
  102. extern void copy_to_user_page(struct vm_area_struct *, struct page *,
  103. unsigned long, void *, const void *, unsigned long);
  104. #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
  105. do { \
  106. memcpy(dst, src, len); \
  107. } while (0)
  108. /*
  109. * Convert calls to our calling convention.
  110. */
  111. /* Invalidate I-cache */
  112. static inline void __flush_icache_all(void)
  113. {
  114. asm("movc p0.c5, %0, #20;\n"
  115. "nop; nop; nop; nop; nop; nop; nop; nop\n"
  116. :
  117. : "r" (0));
  118. }
  119. #define flush_cache_all() __cpuc_flush_kern_all()
  120. extern void flush_cache_mm(struct mm_struct *mm);
  121. extern void flush_cache_range(struct vm_area_struct *vma,
  122. unsigned long start, unsigned long end);
  123. extern void flush_cache_page(struct vm_area_struct *vma,
  124. unsigned long user_addr, unsigned long pfn);
  125. #define flush_cache_dup_mm(mm) flush_cache_mm(mm)
  126. /*
  127. * flush_cache_user_range is used when we want to ensure that the
  128. * Harvard caches are synchronised for the user space address range.
  129. * This is used for the UniCore private sys_cacheflush system call.
  130. */
  131. #define flush_cache_user_range(vma, start, end) \
  132. __cpuc_coherent_user_range((start) & PAGE_MASK, PAGE_ALIGN(end))
  133. /*
  134. * Perform necessary cache operations to ensure that data previously
  135. * stored within this range of addresses can be executed by the CPU.
  136. */
  137. #define flush_icache_range(s, e) __cpuc_coherent_kern_range(s, e)
  138. /*
  139. * Perform necessary cache operations to ensure that the TLB will
  140. * see data written in the specified area.
  141. */
  142. #define clean_dcache_area(start, size) cpu_dcache_clean_area(start, size)
  143. /*
  144. * flush_dcache_page is used when the kernel has written to the page
  145. * cache page at virtual address page->virtual.
  146. *
  147. * If this page isn't mapped (ie, page_mapping == NULL), or it might
  148. * have userspace mappings, then we _must_ always clean + invalidate
  149. * the dcache entries associated with the kernel mapping.
  150. *
  151. * Otherwise we can defer the operation, and clean the cache when we are
  152. * about to change to user space. This is the same method as used on SPARC64.
  153. * See update_mmu_cache for the user space part.
  154. */
  155. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
  156. extern void flush_dcache_page(struct page *);
  157. #define flush_dcache_mmap_lock(mapping) do { } while (0)
  158. #define flush_dcache_mmap_unlock(mapping) do { } while (0)
  159. #define flush_icache_user_range(vma, page, addr, len) \
  160. flush_dcache_page(page)
  161. /*
  162. * We don't appear to need to do anything here. In fact, if we did, we'd
  163. * duplicate cache flushing elsewhere performed by flush_dcache_page().
  164. */
  165. #define flush_icache_page(vma, page) do { } while (0)
  166. /*
  167. * flush_cache_vmap() is used when creating mappings (eg, via vmap,
  168. * vmalloc, ioremap etc) in kernel space for pages. On non-VIPT
  169. * caches, since the direct-mappings of these pages may contain cached
  170. * data, we need to do a full cache flush to ensure that writebacks
  171. * don't corrupt data placed into these pages via the new mappings.
  172. */
  173. static inline void flush_cache_vmap(unsigned long start, unsigned long end)
  174. {
  175. }
  176. static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
  177. {
  178. }
  179. #endif