cacheflush.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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/cachetlb.txt 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. * These are private to the dma-mapping API. Do not use directly.
  99. * Their sole purpose is to ensure that data held in the cache
  100. * is visible to DMA, or data written by DMA to system memory is
  101. * visible to the CPU.
  102. */
  103. extern void __cpuc_dma_clean_range(unsigned long, unsigned long);
  104. extern void __cpuc_dma_flush_range(unsigned long, unsigned long);
  105. /*
  106. * Copy user data from/to a page which is mapped into a different
  107. * processes address space. Really, we want to allow our "user
  108. * space" model to handle this.
  109. */
  110. extern void copy_to_user_page(struct vm_area_struct *, struct page *,
  111. unsigned long, void *, const void *, unsigned long);
  112. #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
  113. do { \
  114. memcpy(dst, src, len); \
  115. } while (0)
  116. /*
  117. * Convert calls to our calling convention.
  118. */
  119. /* Invalidate I-cache */
  120. static inline void __flush_icache_all(void)
  121. {
  122. asm("movc p0.c5, %0, #20;\n"
  123. "nop; nop; nop; nop; nop; nop; nop; nop\n"
  124. :
  125. : "r" (0));
  126. }
  127. #define flush_cache_all() __cpuc_flush_kern_all()
  128. extern void flush_cache_mm(struct mm_struct *mm);
  129. extern void flush_cache_range(struct vm_area_struct *vma,
  130. unsigned long start, unsigned long end);
  131. extern void flush_cache_page(struct vm_area_struct *vma,
  132. unsigned long user_addr, unsigned long pfn);
  133. #define flush_cache_dup_mm(mm) flush_cache_mm(mm)
  134. /*
  135. * flush_cache_user_range is used when we want to ensure that the
  136. * Harvard caches are synchronised for the user space address range.
  137. * This is used for the UniCore private sys_cacheflush system call.
  138. */
  139. #define flush_cache_user_range(vma, start, end) \
  140. __cpuc_coherent_user_range((start) & PAGE_MASK, PAGE_ALIGN(end))
  141. /*
  142. * Perform necessary cache operations to ensure that data previously
  143. * stored within this range of addresses can be executed by the CPU.
  144. */
  145. #define flush_icache_range(s, e) __cpuc_coherent_kern_range(s, e)
  146. /*
  147. * Perform necessary cache operations to ensure that the TLB will
  148. * see data written in the specified area.
  149. */
  150. #define clean_dcache_area(start, size) cpu_dcache_clean_area(start, size)
  151. /*
  152. * flush_dcache_page is used when the kernel has written to the page
  153. * cache page at virtual address page->virtual.
  154. *
  155. * If this page isn't mapped (ie, page_mapping == NULL), or it might
  156. * have userspace mappings, then we _must_ always clean + invalidate
  157. * the dcache entries associated with the kernel mapping.
  158. *
  159. * Otherwise we can defer the operation, and clean the cache when we are
  160. * about to change to user space. This is the same method as used on SPARC64.
  161. * See update_mmu_cache for the user space part.
  162. */
  163. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
  164. extern void flush_dcache_page(struct page *);
  165. #define flush_dcache_mmap_lock(mapping) \
  166. spin_lock_irq(&(mapping)->tree_lock)
  167. #define flush_dcache_mmap_unlock(mapping) \
  168. spin_unlock_irq(&(mapping)->tree_lock)
  169. #define flush_icache_user_range(vma, page, addr, len) \
  170. flush_dcache_page(page)
  171. /*
  172. * We don't appear to need to do anything here. In fact, if we did, we'd
  173. * duplicate cache flushing elsewhere performed by flush_dcache_page().
  174. */
  175. #define flush_icache_page(vma, page) do { } while (0)
  176. /*
  177. * flush_cache_vmap() is used when creating mappings (eg, via vmap,
  178. * vmalloc, ioremap etc) in kernel space for pages. On non-VIPT
  179. * caches, since the direct-mappings of these pages may contain cached
  180. * data, we need to do a full cache flush to ensure that writebacks
  181. * don't corrupt data placed into these pages via the new mappings.
  182. */
  183. static inline void flush_cache_vmap(unsigned long start, unsigned long end)
  184. {
  185. }
  186. static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
  187. {
  188. }
  189. #endif