tlbflush_64.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * arch/sh/mm/tlb-flush_64.c
  3. *
  4. * Copyright (C) 2000, 2001 Paolo Alberelli
  5. * Copyright (C) 2003 Richard Curnow (/proc/tlb, bug fixes)
  6. * Copyright (C) 2003 - 2012 Paul Mundt
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/signal.h>
  13. #include <linux/rwsem.h>
  14. #include <linux/sched.h>
  15. #include <linux/kernel.h>
  16. #include <linux/errno.h>
  17. #include <linux/string.h>
  18. #include <linux/types.h>
  19. #include <linux/ptrace.h>
  20. #include <linux/mman.h>
  21. #include <linux/mm.h>
  22. #include <linux/smp.h>
  23. #include <linux/perf_event.h>
  24. #include <linux/interrupt.h>
  25. #include <asm/io.h>
  26. #include <asm/tlb.h>
  27. #include <asm/uaccess.h>
  28. #include <asm/pgalloc.h>
  29. #include <asm/mmu_context.h>
  30. void local_flush_tlb_one(unsigned long asid, unsigned long page)
  31. {
  32. unsigned long long match, pteh=0, lpage;
  33. unsigned long tlb;
  34. /*
  35. * Sign-extend based on neff.
  36. */
  37. lpage = neff_sign_extend(page);
  38. match = (asid << PTEH_ASID_SHIFT) | PTEH_VALID;
  39. match |= lpage;
  40. for_each_itlb_entry(tlb) {
  41. asm volatile ("getcfg %1, 0, %0"
  42. : "=r" (pteh)
  43. : "r" (tlb) );
  44. if (pteh == match) {
  45. __flush_tlb_slot(tlb);
  46. break;
  47. }
  48. }
  49. for_each_dtlb_entry(tlb) {
  50. asm volatile ("getcfg %1, 0, %0"
  51. : "=r" (pteh)
  52. : "r" (tlb) );
  53. if (pteh == match) {
  54. __flush_tlb_slot(tlb);
  55. break;
  56. }
  57. }
  58. }
  59. void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  60. {
  61. unsigned long flags;
  62. if (vma->vm_mm) {
  63. page &= PAGE_MASK;
  64. local_irq_save(flags);
  65. local_flush_tlb_one(get_asid(), page);
  66. local_irq_restore(flags);
  67. }
  68. }
  69. void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  70. unsigned long end)
  71. {
  72. unsigned long flags;
  73. unsigned long long match, pteh=0, pteh_epn, pteh_low;
  74. unsigned long tlb;
  75. unsigned int cpu = smp_processor_id();
  76. struct mm_struct *mm;
  77. mm = vma->vm_mm;
  78. if (cpu_context(cpu, mm) == NO_CONTEXT)
  79. return;
  80. local_irq_save(flags);
  81. start &= PAGE_MASK;
  82. end &= PAGE_MASK;
  83. match = (cpu_asid(cpu, mm) << PTEH_ASID_SHIFT) | PTEH_VALID;
  84. /* Flush ITLB */
  85. for_each_itlb_entry(tlb) {
  86. asm volatile ("getcfg %1, 0, %0"
  87. : "=r" (pteh)
  88. : "r" (tlb) );
  89. pteh_epn = pteh & PAGE_MASK;
  90. pteh_low = pteh & ~PAGE_MASK;
  91. if (pteh_low == match && pteh_epn >= start && pteh_epn <= end)
  92. __flush_tlb_slot(tlb);
  93. }
  94. /* Flush DTLB */
  95. for_each_dtlb_entry(tlb) {
  96. asm volatile ("getcfg %1, 0, %0"
  97. : "=r" (pteh)
  98. : "r" (tlb) );
  99. pteh_epn = pteh & PAGE_MASK;
  100. pteh_low = pteh & ~PAGE_MASK;
  101. if (pteh_low == match && pteh_epn >= start && pteh_epn <= end)
  102. __flush_tlb_slot(tlb);
  103. }
  104. local_irq_restore(flags);
  105. }
  106. void local_flush_tlb_mm(struct mm_struct *mm)
  107. {
  108. unsigned long flags;
  109. unsigned int cpu = smp_processor_id();
  110. if (cpu_context(cpu, mm) == NO_CONTEXT)
  111. return;
  112. local_irq_save(flags);
  113. cpu_context(cpu, mm) = NO_CONTEXT;
  114. if (mm == current->mm)
  115. activate_context(mm, cpu);
  116. local_irq_restore(flags);
  117. }
  118. void local_flush_tlb_all(void)
  119. {
  120. /* Invalidate all, including shared pages, excluding fixed TLBs */
  121. unsigned long flags, tlb;
  122. local_irq_save(flags);
  123. /* Flush each ITLB entry */
  124. for_each_itlb_entry(tlb)
  125. __flush_tlb_slot(tlb);
  126. /* Flush each DTLB entry */
  127. for_each_dtlb_entry(tlb)
  128. __flush_tlb_slot(tlb);
  129. local_irq_restore(flags);
  130. }
  131. void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
  132. {
  133. /* FIXME: Optimize this later.. */
  134. flush_tlb_all();
  135. }
  136. void __flush_tlb_global(void)
  137. {
  138. flush_tlb_all();
  139. }