cacheflush.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #ifndef _PARISC_CACHEFLUSH_H
  2. #define _PARISC_CACHEFLUSH_H
  3. #include <linux/config.h>
  4. #include <linux/mm.h>
  5. #include <asm/cache.h> /* for flush_user_dcache_range_asm() proto */
  6. /* The usual comment is "Caches aren't brain-dead on the <architecture>".
  7. * Unfortunately, that doesn't apply to PA-RISC. */
  8. /* Cache flush operations */
  9. #ifdef CONFIG_SMP
  10. #define flush_cache_mm(mm) flush_cache_all()
  11. #else
  12. #define flush_cache_mm(mm) flush_cache_all_local()
  13. #endif
  14. #define flush_kernel_dcache_range(start,size) \
  15. flush_kernel_dcache_range_asm((start), (start)+(size));
  16. extern void flush_cache_all_local(void);
  17. static inline void cacheflush_h_tmp_function(void *dummy)
  18. {
  19. flush_cache_all_local();
  20. }
  21. static inline void flush_cache_all(void)
  22. {
  23. on_each_cpu(cacheflush_h_tmp_function, NULL, 1, 1);
  24. }
  25. #define flush_cache_vmap(start, end) flush_cache_all()
  26. #define flush_cache_vunmap(start, end) flush_cache_all()
  27. extern int parisc_cache_flush_threshold;
  28. void parisc_setup_cache_timing(void);
  29. static inline void
  30. flush_user_dcache_range(unsigned long start, unsigned long end)
  31. {
  32. if ((end - start) < parisc_cache_flush_threshold)
  33. flush_user_dcache_range_asm(start,end);
  34. else
  35. flush_data_cache();
  36. }
  37. static inline void
  38. flush_user_icache_range(unsigned long start, unsigned long end)
  39. {
  40. if ((end - start) < parisc_cache_flush_threshold)
  41. flush_user_icache_range_asm(start,end);
  42. else
  43. flush_instruction_cache();
  44. }
  45. extern void flush_dcache_page(struct page *page);
  46. #define flush_dcache_mmap_lock(mapping) \
  47. write_lock_irq(&(mapping)->tree_lock)
  48. #define flush_dcache_mmap_unlock(mapping) \
  49. write_unlock_irq(&(mapping)->tree_lock)
  50. #define flush_icache_page(vma,page) do { flush_kernel_dcache_page(page); flush_kernel_icache_page(page_address(page)); } while (0)
  51. #define flush_icache_range(s,e) do { flush_kernel_dcache_range_asm(s,e); flush_kernel_icache_range_asm(s,e); } while (0)
  52. #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
  53. do { \
  54. flush_cache_page(vma, vaddr, page_to_pfn(page)); \
  55. memcpy(dst, src, len); \
  56. flush_kernel_dcache_range_asm((unsigned long)dst, (unsigned long)dst + len); \
  57. } while (0)
  58. #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
  59. do { \
  60. flush_cache_page(vma, vaddr, page_to_pfn(page)); \
  61. memcpy(dst, src, len); \
  62. } while (0)
  63. static inline void flush_cache_range(struct vm_area_struct *vma,
  64. unsigned long start, unsigned long end)
  65. {
  66. int sr3;
  67. if (!vma->vm_mm->context) {
  68. BUG();
  69. return;
  70. }
  71. sr3 = mfsp(3);
  72. if (vma->vm_mm->context == sr3) {
  73. flush_user_dcache_range(start,end);
  74. flush_user_icache_range(start,end);
  75. } else {
  76. flush_cache_all();
  77. }
  78. }
  79. /* Simple function to work out if we have an existing address translation
  80. * for a user space vma. */
  81. static inline int translation_exists(struct vm_area_struct *vma,
  82. unsigned long addr, unsigned long pfn)
  83. {
  84. pgd_t *pgd = pgd_offset(vma->vm_mm, addr);
  85. pmd_t *pmd;
  86. pte_t pte;
  87. if(pgd_none(*pgd))
  88. return 0;
  89. pmd = pmd_offset(pgd, addr);
  90. if(pmd_none(*pmd) || pmd_bad(*pmd))
  91. return 0;
  92. /* We cannot take the pte lock here: flush_cache_page is usually
  93. * called with pte lock already held. Whereas flush_dcache_page
  94. * takes flush_dcache_mmap_lock, which is lower in the hierarchy:
  95. * the vma itself is secure, but the pte might come or go racily.
  96. */
  97. pte = *pte_offset_map(pmd, addr);
  98. /* But pte_unmap() does nothing on this architecture */
  99. /* Filter out coincidental file entries and swap entries */
  100. if (!(pte_val(pte) & (_PAGE_FLUSH|_PAGE_PRESENT)))
  101. return 0;
  102. return pte_pfn(pte) == pfn;
  103. }
  104. /* Private function to flush a page from the cache of a non-current
  105. * process. cr25 contains the Page Directory of the current user
  106. * process; we're going to hijack both it and the user space %sr3 to
  107. * temporarily make the non-current process current. We have to do
  108. * this because cache flushing may cause a non-access tlb miss which
  109. * the handlers have to fill in from the pgd of the non-current
  110. * process. */
  111. static inline void
  112. flush_user_cache_page_non_current(struct vm_area_struct *vma,
  113. unsigned long vmaddr)
  114. {
  115. /* save the current process space and pgd */
  116. unsigned long space = mfsp(3), pgd = mfctl(25);
  117. /* we don't mind taking interrups since they may not
  118. * do anything with user space, but we can't
  119. * be preempted here */
  120. preempt_disable();
  121. /* make us current */
  122. mtctl(__pa(vma->vm_mm->pgd), 25);
  123. mtsp(vma->vm_mm->context, 3);
  124. flush_user_dcache_page(vmaddr);
  125. if(vma->vm_flags & VM_EXEC)
  126. flush_user_icache_page(vmaddr);
  127. /* put the old current process back */
  128. mtsp(space, 3);
  129. mtctl(pgd, 25);
  130. preempt_enable();
  131. }
  132. static inline void
  133. __flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr)
  134. {
  135. if (likely(vma->vm_mm->context == mfsp(3))) {
  136. flush_user_dcache_page(vmaddr);
  137. if (vma->vm_flags & VM_EXEC)
  138. flush_user_icache_page(vmaddr);
  139. } else {
  140. flush_user_cache_page_non_current(vma, vmaddr);
  141. }
  142. }
  143. static inline void
  144. flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn)
  145. {
  146. BUG_ON(!vma->vm_mm->context);
  147. if (likely(translation_exists(vma, vmaddr, pfn)))
  148. __flush_cache_page(vma, vmaddr);
  149. }
  150. static inline void
  151. flush_anon_page(struct page *page, unsigned long vmaddr)
  152. {
  153. if (PageAnon(page))
  154. flush_user_dcache_page(vmaddr);
  155. }
  156. #define ARCH_HAS_FLUSH_ANON_PAGE
  157. static inline void
  158. flush_kernel_dcache_page(struct page *page)
  159. {
  160. flush_kernel_dcache_page_asm(page_address(page));
  161. }
  162. #define ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
  163. #ifdef CONFIG_DEBUG_RODATA
  164. void mark_rodata_ro(void);
  165. #endif
  166. #endif /* _PARISC_CACHEFLUSH_H */