tlb.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. /*
  12. * TLB handling. This allows us to remove pages from the page
  13. * tables, and efficiently handle the TLB issues.
  14. */
  15. struct mmu_gather {
  16. struct mm_struct *mm;
  17. unsigned int fullmm;
  18. unsigned long start, end;
  19. };
  20. DECLARE_PER_CPU(struct mmu_gather, mmu_gathers);
  21. static inline void init_tlb_gather(struct mmu_gather *tlb)
  22. {
  23. tlb->start = TASK_SIZE;
  24. tlb->end = 0;
  25. if (tlb->fullmm) {
  26. tlb->start = 0;
  27. tlb->end = TASK_SIZE;
  28. }
  29. }
  30. static inline struct mmu_gather *
  31. tlb_gather_mmu(struct mm_struct *mm, unsigned int full_mm_flush)
  32. {
  33. struct mmu_gather *tlb = &get_cpu_var(mmu_gathers);
  34. tlb->mm = mm;
  35. tlb->fullmm = full_mm_flush;
  36. init_tlb_gather(tlb);
  37. return tlb;
  38. }
  39. static inline void
  40. tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
  41. {
  42. if (tlb->fullmm)
  43. flush_tlb_mm(tlb->mm);
  44. /* keep the page table cache within bounds */
  45. check_pgt_cache();
  46. put_cpu_var(mmu_gathers);
  47. }
  48. static inline void
  49. tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, unsigned long address)
  50. {
  51. if (tlb->start > address)
  52. tlb->start = address;
  53. if (tlb->end < address + PAGE_SIZE)
  54. tlb->end = address + PAGE_SIZE;
  55. }
  56. /*
  57. * In the case of tlb vma handling, we can optimise these away in the
  58. * case where we're doing a full MM flush. When we're doing a munmap,
  59. * the vmas are adjusted to only cover the region to be torn down.
  60. */
  61. static inline void
  62. tlb_start_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
  63. {
  64. if (!tlb->fullmm)
  65. flush_cache_range(vma, vma->vm_start, vma->vm_end);
  66. }
  67. static inline void
  68. tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
  69. {
  70. if (!tlb->fullmm && tlb->end) {
  71. flush_tlb_range(vma, tlb->start, tlb->end);
  72. init_tlb_gather(tlb);
  73. }
  74. }
  75. #define tlb_remove_page(tlb,page) free_page_and_swap_cache(page)
  76. #define pte_free_tlb(tlb, ptep) pte_free((tlb)->mm, ptep)
  77. #define pmd_free_tlb(tlb, pmdp) pmd_free((tlb)->mm, pmdp)
  78. #define pud_free_tlb(tlb, pudp) pud_free((tlb)->mm, pudp)
  79. #define tlb_migrate_finish(mm) do { } while (0)
  80. #else /* CONFIG_MMU */
  81. #define tlb_start_vma(tlb, vma) do { } while (0)
  82. #define tlb_end_vma(tlb, vma) do { } while (0)
  83. #define __tlb_remove_tlb_entry(tlb, pte, address) do { } while (0)
  84. #define tlb_flush(tlb) do { } while (0)
  85. #include <asm-generic/tlb.h>
  86. #endif /* CONFIG_MMU */
  87. #endif /* __ASSEMBLY__ */
  88. #endif /* __ASM_SH_TLB_H */