tlbflush.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 flush_tlb_all(void)
  64. {
  65. dsb(ishst);
  66. asm("tlbi vmalle1is");
  67. dsb(ish);
  68. isb();
  69. }
  70. static inline void flush_tlb_mm(struct mm_struct *mm)
  71. {
  72. unsigned long asid = (unsigned long)ASID(mm) << 48;
  73. dsb(ishst);
  74. asm("tlbi aside1is, %0" : : "r" (asid));
  75. dsb(ish);
  76. }
  77. static inline void flush_tlb_page(struct vm_area_struct *vma,
  78. unsigned long uaddr)
  79. {
  80. unsigned long addr = uaddr >> 12 |
  81. ((unsigned long)ASID(vma->vm_mm) << 48);
  82. dsb(ishst);
  83. asm("tlbi vale1is, %0" : : "r" (addr));
  84. dsb(ish);
  85. }
  86. /*
  87. * This is meant to avoid soft lock-ups on large TLB flushing ranges and not
  88. * necessarily a performance improvement.
  89. */
  90. #define MAX_TLB_RANGE (1024UL << PAGE_SHIFT)
  91. static inline void __flush_tlb_range(struct vm_area_struct *vma,
  92. unsigned long start, unsigned long end,
  93. bool last_level)
  94. {
  95. unsigned long asid = (unsigned long)ASID(vma->vm_mm) << 48;
  96. unsigned long addr;
  97. if ((end - start) > MAX_TLB_RANGE) {
  98. flush_tlb_mm(vma->vm_mm);
  99. return;
  100. }
  101. start = asid | (start >> 12);
  102. end = asid | (end >> 12);
  103. dsb(ishst);
  104. for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12)) {
  105. if (last_level)
  106. asm("tlbi vale1is, %0" : : "r"(addr));
  107. else
  108. asm("tlbi vae1is, %0" : : "r"(addr));
  109. }
  110. dsb(ish);
  111. }
  112. static inline void flush_tlb_range(struct vm_area_struct *vma,
  113. unsigned long start, unsigned long end)
  114. {
  115. __flush_tlb_range(vma, start, end, false);
  116. }
  117. static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
  118. {
  119. unsigned long addr;
  120. if ((end - start) > MAX_TLB_RANGE) {
  121. flush_tlb_all();
  122. return;
  123. }
  124. start >>= 12;
  125. end >>= 12;
  126. dsb(ishst);
  127. for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12))
  128. asm("tlbi vaae1is, %0" : : "r"(addr));
  129. dsb(ish);
  130. isb();
  131. }
  132. /*
  133. * Used to invalidate the TLB (walk caches) corresponding to intermediate page
  134. * table levels (pgd/pud/pmd).
  135. */
  136. static inline void __flush_tlb_pgtable(struct mm_struct *mm,
  137. unsigned long uaddr)
  138. {
  139. unsigned long addr = uaddr >> 12 | ((unsigned long)ASID(mm) << 48);
  140. dsb(ishst);
  141. asm("tlbi vae1is, %0" : : "r" (addr));
  142. dsb(ish);
  143. }
  144. #endif
  145. #endif