cacheflush.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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_address(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 pte_t *__translation_exists(struct mm_struct *mm,
  82. unsigned long addr)
  83. {
  84. pgd_t *pgd = pgd_offset(mm, addr);
  85. pmd_t *pmd;
  86. pte_t *pte;
  87. if(pgd_none(*pgd))
  88. return NULL;
  89. pmd = pmd_offset(pgd, addr);
  90. if(pmd_none(*pmd) || pmd_bad(*pmd))
  91. return NULL;
  92. pte = pte_offset_map(pmd, addr);
  93. /* The PA flush mappings show up as pte_none, but they're
  94. * valid none the less */
  95. if(pte_none(*pte) && ((pte_val(*pte) & _PAGE_FLUSH) == 0))
  96. return NULL;
  97. return pte;
  98. }
  99. #define translation_exists(vma, addr) __translation_exists((vma)->vm_mm, addr)
  100. /* Private function to flush a page from the cache of a non-current
  101. * process. cr25 contains the Page Directory of the current user
  102. * process; we're going to hijack both it and the user space %sr3 to
  103. * temporarily make the non-current process current. We have to do
  104. * this because cache flushing may cause a non-access tlb miss which
  105. * the handlers have to fill in from the pgd of the non-current
  106. * process. */
  107. static inline void
  108. flush_user_cache_page_non_current(struct vm_area_struct *vma,
  109. unsigned long vmaddr)
  110. {
  111. /* save the current process space and pgd */
  112. unsigned long space = mfsp(3), pgd = mfctl(25);
  113. /* we don't mind taking interrups since they may not
  114. * do anything with user space, but we can't
  115. * be preempted here */
  116. preempt_disable();
  117. /* make us current */
  118. mtctl(__pa(vma->vm_mm->pgd), 25);
  119. mtsp(vma->vm_mm->context, 3);
  120. flush_user_dcache_page(vmaddr);
  121. if(vma->vm_flags & VM_EXEC)
  122. flush_user_icache_page(vmaddr);
  123. /* put the old current process back */
  124. mtsp(space, 3);
  125. mtctl(pgd, 25);
  126. preempt_enable();
  127. }
  128. static inline void
  129. __flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr)
  130. {
  131. if (likely(vma->vm_mm->context == mfsp(3))) {
  132. flush_user_dcache_page(vmaddr);
  133. if (vma->vm_flags & VM_EXEC)
  134. flush_user_icache_page(vmaddr);
  135. } else {
  136. flush_user_cache_page_non_current(vma, vmaddr);
  137. }
  138. }
  139. static inline void
  140. flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn)
  141. {
  142. BUG_ON(!vma->vm_mm->context);
  143. if(likely(translation_exists(vma, vmaddr)))
  144. __flush_cache_page(vma, vmaddr);
  145. }
  146. #endif