tlb.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_SH_TLB_H
  3. #define __ASM_SH_TLB_H
  4. #ifdef CONFIG_SUPERH64
  5. # include <asm/tlb_64.h>
  6. #endif
  7. #ifndef __ASSEMBLY__
  8. #include <linux/pagemap.h>
  9. #ifdef CONFIG_MMU
  10. #include <linux/swap.h>
  11. #include <asm/pgalloc.h>
  12. #include <asm/tlbflush.h>
  13. #include <asm/mmu_context.h>
  14. /*
  15. * TLB handling. This allows us to remove pages from the page
  16. * tables, and efficiently handle the TLB issues.
  17. */
  18. struct mmu_gather {
  19. struct mm_struct *mm;
  20. unsigned int fullmm;
  21. unsigned long start, end;
  22. };
  23. static inline void init_tlb_gather(struct mmu_gather *tlb)
  24. {
  25. tlb->start = TASK_SIZE;
  26. tlb->end = 0;
  27. if (tlb->fullmm) {
  28. tlb->start = 0;
  29. tlb->end = TASK_SIZE;
  30. }
  31. }
  32. static inline void
  33. arch_tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,
  34. unsigned long start, unsigned long end)
  35. {
  36. tlb->mm = mm;
  37. tlb->start = start;
  38. tlb->end = end;
  39. tlb->fullmm = !(start | (end+1));
  40. init_tlb_gather(tlb);
  41. }
  42. static inline void
  43. arch_tlb_finish_mmu(struct mmu_gather *tlb,
  44. unsigned long start, unsigned long end, bool force)
  45. {
  46. if (tlb->fullmm || force)
  47. flush_tlb_mm(tlb->mm);
  48. /* keep the page table cache within bounds */
  49. check_pgt_cache();
  50. }
  51. static inline void
  52. tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, unsigned long address)
  53. {
  54. if (tlb->start > address)
  55. tlb->start = address;
  56. if (tlb->end < address + PAGE_SIZE)
  57. tlb->end = address + PAGE_SIZE;
  58. }
  59. #define tlb_remove_huge_tlb_entry(h, tlb, ptep, address) \
  60. tlb_remove_tlb_entry(tlb, ptep, address)
  61. /*
  62. * In the case of tlb vma handling, we can optimise these away in the
  63. * case where we're doing a full MM flush. When we're doing a munmap,
  64. * the vmas are adjusted to only cover the region to be torn down.
  65. */
  66. static inline void
  67. tlb_start_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
  68. {
  69. if (!tlb->fullmm)
  70. flush_cache_range(vma, vma->vm_start, vma->vm_end);
  71. }
  72. static inline void
  73. tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
  74. {
  75. if (!tlb->fullmm && tlb->end) {
  76. flush_tlb_range(vma, tlb->start, tlb->end);
  77. init_tlb_gather(tlb);
  78. }
  79. }
  80. static inline void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb)
  81. {
  82. }
  83. static inline void tlb_flush_mmu_free(struct mmu_gather *tlb)
  84. {
  85. }
  86. static inline void tlb_flush_mmu(struct mmu_gather *tlb)
  87. {
  88. }
  89. static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  90. {
  91. free_page_and_swap_cache(page);
  92. return false; /* avoid calling tlb_flush_mmu */
  93. }
  94. static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  95. {
  96. __tlb_remove_page(tlb, page);
  97. }
  98. static inline bool __tlb_remove_page_size(struct mmu_gather *tlb,
  99. struct page *page, int page_size)
  100. {
  101. return __tlb_remove_page(tlb, page);
  102. }
  103. static inline void tlb_remove_page_size(struct mmu_gather *tlb,
  104. struct page *page, int page_size)
  105. {
  106. return tlb_remove_page(tlb, page);
  107. }
  108. #define tlb_remove_check_page_size_change tlb_remove_check_page_size_change
  109. static inline void tlb_remove_check_page_size_change(struct mmu_gather *tlb,
  110. unsigned int page_size)
  111. {
  112. }
  113. #define pte_free_tlb(tlb, ptep, addr) pte_free((tlb)->mm, ptep)
  114. #define pmd_free_tlb(tlb, pmdp, addr) pmd_free((tlb)->mm, pmdp)
  115. #define pud_free_tlb(tlb, pudp, addr) pud_free((tlb)->mm, pudp)
  116. #define tlb_migrate_finish(mm) do { } while (0)
  117. #if defined(CONFIG_CPU_SH4) || defined(CONFIG_SUPERH64)
  118. extern void tlb_wire_entry(struct vm_area_struct *, unsigned long, pte_t);
  119. extern void tlb_unwire_entry(void);
  120. #else
  121. static inline void tlb_wire_entry(struct vm_area_struct *vma ,
  122. unsigned long addr, pte_t pte)
  123. {
  124. BUG();
  125. }
  126. static inline void tlb_unwire_entry(void)
  127. {
  128. BUG();
  129. }
  130. #endif
  131. #else /* CONFIG_MMU */
  132. #define tlb_start_vma(tlb, vma) do { } while (0)
  133. #define tlb_end_vma(tlb, vma) do { } while (0)
  134. #define __tlb_remove_tlb_entry(tlb, pte, address) do { } while (0)
  135. #define tlb_flush(tlb) do { } while (0)
  136. #include <asm-generic/tlb.h>
  137. #endif /* CONFIG_MMU */
  138. #endif /* __ASSEMBLY__ */
  139. #endif /* __ASM_SH_TLB_H */