tlb.h 3.7 KB

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