tlbflush.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Based on arch/arm/include/asm/tlbflush.h
  3. *
  4. * Copyright (C) 1999-2003 Russell King
  5. * Copyright (C) 2012 ARM Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __ASM_TLBFLUSH_H
  20. #define __ASM_TLBFLUSH_H
  21. #ifndef __ASSEMBLY__
  22. #include <linux/sched.h>
  23. #include <asm/cputype.h>
  24. /*
  25. * TLB Management
  26. * ==============
  27. *
  28. * The TLB specific code is expected to perform whatever tests it needs
  29. * to determine if it should invalidate the TLB for each call. Start
  30. * addresses are inclusive and end addresses are exclusive; it is safe to
  31. * round these addresses down.
  32. *
  33. * flush_tlb_all()
  34. *
  35. * Invalidate the entire TLB.
  36. *
  37. * flush_tlb_mm(mm)
  38. *
  39. * Invalidate all TLB entries in a particular address space.
  40. * - mm - mm_struct describing address space
  41. *
  42. * flush_tlb_range(mm,start,end)
  43. *
  44. * Invalidate a range of TLB entries in the specified address
  45. * space.
  46. * - mm - mm_struct describing address space
  47. * - start - start address (may not be aligned)
  48. * - end - end address (exclusive, may not be aligned)
  49. *
  50. * flush_tlb_page(vaddr,vma)
  51. *
  52. * Invalidate the specified page in the specified address range.
  53. * - vaddr - virtual address (may not be aligned)
  54. * - vma - vma_struct describing address range
  55. *
  56. * flush_kern_tlb_page(kaddr)
  57. *
  58. * Invalidate the TLB entry for the specified page. The address
  59. * will be in the kernels virtual memory space. Current uses
  60. * only require the D-TLB to be invalidated.
  61. * - kaddr - Kernel virtual memory address
  62. */
  63. static inline void local_flush_tlb_all(void)
  64. {
  65. dsb(nshst);
  66. asm("tlbi vmalle1");
  67. dsb(nsh);
  68. isb();
  69. }
  70. static inline void flush_tlb_all(void)
  71. {
  72. dsb(ishst);
  73. asm("tlbi vmalle1is");
  74. dsb(ish);
  75. isb();
  76. }
  77. static inline void flush_tlb_mm(struct mm_struct *mm)
  78. {
  79. unsigned long asid = ASID(mm) << 48;
  80. dsb(ishst);
  81. asm("tlbi aside1is, %0" : : "r" (asid));
  82. dsb(ish);
  83. }
  84. static inline void flush_tlb_page(struct vm_area_struct *vma,
  85. unsigned long uaddr)
  86. {
  87. unsigned long addr = uaddr >> 12 | (ASID(vma->vm_mm) << 48);
  88. dsb(ishst);
  89. asm("tlbi vale1is, %0" : : "r" (addr));
  90. dsb(ish);
  91. }
  92. /*
  93. * This is meant to avoid soft lock-ups on large TLB flushing ranges and not
  94. * necessarily a performance improvement.
  95. */
  96. #define MAX_TLB_RANGE (1024UL << PAGE_SHIFT)
  97. static inline void __flush_tlb_range(struct vm_area_struct *vma,
  98. unsigned long start, unsigned long end,
  99. bool last_level)
  100. {
  101. unsigned long asid = ASID(vma->vm_mm) << 48;
  102. unsigned long addr;
  103. if ((end - start) > MAX_TLB_RANGE) {
  104. flush_tlb_mm(vma->vm_mm);
  105. return;
  106. }
  107. start = asid | (start >> 12);
  108. end = asid | (end >> 12);
  109. dsb(ishst);
  110. for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12)) {
  111. if (last_level)
  112. asm("tlbi vale1is, %0" : : "r"(addr));
  113. else
  114. asm("tlbi vae1is, %0" : : "r"(addr));
  115. }
  116. dsb(ish);
  117. }
  118. static inline void flush_tlb_range(struct vm_area_struct *vma,
  119. unsigned long start, unsigned long end)
  120. {
  121. __flush_tlb_range(vma, start, end, false);
  122. }
  123. static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
  124. {
  125. unsigned long addr;
  126. if ((end - start) > MAX_TLB_RANGE) {
  127. flush_tlb_all();
  128. return;
  129. }
  130. start >>= 12;
  131. end >>= 12;
  132. dsb(ishst);
  133. for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12))
  134. asm("tlbi vaae1is, %0" : : "r"(addr));
  135. dsb(ish);
  136. isb();
  137. }
  138. /*
  139. * Used to invalidate the TLB (walk caches) corresponding to intermediate page
  140. * table levels (pgd/pud/pmd).
  141. */
  142. static inline void __flush_tlb_pgtable(struct mm_struct *mm,
  143. unsigned long uaddr)
  144. {
  145. unsigned long addr = uaddr >> 12 | (ASID(mm) << 48);
  146. asm("tlbi vae1is, %0" : : "r" (addr));
  147. dsb(ish);
  148. }
  149. #endif
  150. #endif