PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/ia64/include/asm/tlb.h

https://gitlab.com/Sean.W/pru-linux-drivers
C Header | 257 lines | 133 code | 28 blank | 96 comment | 21 complexity | 4e17aeb8cd5c6845f4ee9400b5312a1b MD5 | raw file
  1. #ifndef _ASM_IA64_TLB_H
  2. #define _ASM_IA64_TLB_H
  3. /*
  4. * Based on <asm-generic/tlb.h>.
  5. *
  6. * Copyright (C) 2002-2003 Hewlett-Packard Co
  7. * David Mosberger-Tang <davidm@hpl.hp.com>
  8. */
  9. /*
  10. * Removing a translation from a page table (including TLB-shootdown) is a four-step
  11. * procedure:
  12. *
  13. * (1) Flush (virtual) caches --- ensures virtual memory is coherent with kernel memory
  14. * (this is a no-op on ia64).
  15. * (2) Clear the relevant portions of the page-table
  16. * (3) Flush the TLBs --- ensures that stale content is gone from CPU TLBs
  17. * (4) Release the pages that were freed up in step (2).
  18. *
  19. * Note that the ordering of these steps is crucial to avoid races on MP machines.
  20. *
  21. * The Linux kernel defines several platform-specific hooks for TLB-shootdown. When
  22. * unmapping a portion of the virtual address space, these hooks are called according to
  23. * the following template:
  24. *
  25. * tlb <- tlb_gather_mmu(mm, full_mm_flush); // start unmap for address space MM
  26. * {
  27. * for each vma that needs a shootdown do {
  28. * tlb_start_vma(tlb, vma);
  29. * for each page-table-entry PTE that needs to be removed do {
  30. * tlb_remove_tlb_entry(tlb, pte, address);
  31. * if (pte refers to a normal page) {
  32. * tlb_remove_page(tlb, page);
  33. * }
  34. * }
  35. * tlb_end_vma(tlb, vma);
  36. * }
  37. * }
  38. * tlb_finish_mmu(tlb, start, end); // finish unmap for address space MM
  39. */
  40. #include <linux/mm.h>
  41. #include <linux/pagemap.h>
  42. #include <linux/swap.h>
  43. #include <asm/pgalloc.h>
  44. #include <asm/processor.h>
  45. #include <asm/tlbflush.h>
  46. #include <asm/machvec.h>
  47. #ifdef CONFIG_SMP
  48. # define FREE_PTE_NR 2048
  49. # define tlb_fast_mode(tlb) ((tlb)->nr == ~0U)
  50. #else
  51. # define FREE_PTE_NR 0
  52. # define tlb_fast_mode(tlb) (1)
  53. #endif
  54. struct mmu_gather {
  55. struct mm_struct *mm;
  56. unsigned int nr; /* == ~0U => fast mode */
  57. unsigned char fullmm; /* non-zero means full mm flush */
  58. unsigned char need_flush; /* really unmapped some PTEs? */
  59. unsigned long start_addr;
  60. unsigned long end_addr;
  61. struct page *pages[FREE_PTE_NR];
  62. };
  63. struct ia64_tr_entry {
  64. u64 ifa;
  65. u64 itir;
  66. u64 pte;
  67. u64 rr;
  68. }; /*Record for tr entry!*/
  69. extern int ia64_itr_entry(u64 target_mask, u64 va, u64 pte, u64 log_size);
  70. extern void ia64_ptr_entry(u64 target_mask, int slot);
  71. extern struct ia64_tr_entry *ia64_idtrs[NR_CPUS];
  72. /*
  73. region register macros
  74. */
  75. #define RR_TO_VE(val) (((val) >> 0) & 0x0000000000000001)
  76. #define RR_VE(val) (((val) & 0x0000000000000001) << 0)
  77. #define RR_VE_MASK 0x0000000000000001L
  78. #define RR_VE_SHIFT 0
  79. #define RR_TO_PS(val) (((val) >> 2) & 0x000000000000003f)
  80. #define RR_PS(val) (((val) & 0x000000000000003f) << 2)
  81. #define RR_PS_MASK 0x00000000000000fcL
  82. #define RR_PS_SHIFT 2
  83. #define RR_RID_MASK 0x00000000ffffff00L
  84. #define RR_TO_RID(val) ((val >> 8) & 0xffffff)
  85. /* Users of the generic TLB shootdown code must declare this storage space. */
  86. DECLARE_PER_CPU(struct mmu_gather, mmu_gathers);
  87. /*
  88. * Flush the TLB for address range START to END and, if not in fast mode, release the
  89. * freed pages that where gathered up to this point.
  90. */
  91. static inline void
  92. ia64_tlb_flush_mmu (struct mmu_gather *tlb, unsigned long start, unsigned long end)
  93. {
  94. unsigned int nr;
  95. if (!tlb->need_flush)
  96. return;
  97. tlb->need_flush = 0;
  98. if (tlb->fullmm) {
  99. /*
  100. * Tearing down the entire address space. This happens both as a result
  101. * of exit() and execve(). The latter case necessitates the call to
  102. * flush_tlb_mm() here.
  103. */
  104. flush_tlb_mm(tlb->mm);
  105. } else if (unlikely (end - start >= 1024*1024*1024*1024UL
  106. || REGION_NUMBER(start) != REGION_NUMBER(end - 1)))
  107. {
  108. /*
  109. * If we flush more than a tera-byte or across regions, we're probably
  110. * better off just flushing the entire TLB(s). This should be very rare
  111. * and is not worth optimizing for.
  112. */
  113. flush_tlb_all();
  114. } else {
  115. /*
  116. * XXX fix me: flush_tlb_range() should take an mm pointer instead of a
  117. * vma pointer.
  118. */
  119. struct vm_area_struct vma;
  120. vma.vm_mm = tlb->mm;
  121. /* flush the address range from the tlb: */
  122. flush_tlb_range(&vma, start, end);
  123. /* now flush the virt. page-table area mapping the address range: */
  124. flush_tlb_range(&vma, ia64_thash(start), ia64_thash(end));
  125. }
  126. /* lastly, release the freed pages */
  127. nr = tlb->nr;
  128. if (!tlb_fast_mode(tlb)) {
  129. unsigned long i;
  130. tlb->nr = 0;
  131. tlb->start_addr = ~0UL;
  132. for (i = 0; i < nr; ++i)
  133. free_page_and_swap_cache(tlb->pages[i]);
  134. }
  135. }
  136. /*
  137. * Return a pointer to an initialized struct mmu_gather.
  138. */
  139. static inline struct mmu_gather *
  140. tlb_gather_mmu (struct mm_struct *mm, unsigned int full_mm_flush)
  141. {
  142. struct mmu_gather *tlb = &get_cpu_var(mmu_gathers);
  143. tlb->mm = mm;
  144. /*
  145. * Use fast mode if only 1 CPU is online.
  146. *
  147. * It would be tempting to turn on fast-mode for full_mm_flush as well. But this
  148. * doesn't work because of speculative accesses and software prefetching: the page
  149. * table of "mm" may (and usually is) the currently active page table and even
  150. * though the kernel won't do any user-space accesses during the TLB shoot down, a
  151. * compiler might use speculation or lfetch.fault on what happens to be a valid
  152. * user-space address. This in turn could trigger a TLB miss fault (or a VHPT
  153. * walk) and re-insert a TLB entry we just removed. Slow mode avoids such
  154. * problems. (We could make fast-mode work by switching the current task to a
  155. * different "mm" during the shootdown.) --davidm 08/02/2002
  156. */
  157. tlb->nr = (num_online_cpus() == 1) ? ~0U : 0;
  158. tlb->fullmm = full_mm_flush;
  159. tlb->start_addr = ~0UL;
  160. return tlb;
  161. }
  162. /*
  163. * Called at the end of the shootdown operation to free up any resources that were
  164. * collected.
  165. */
  166. static inline void
  167. tlb_finish_mmu (struct mmu_gather *tlb, unsigned long start, unsigned long end)
  168. {
  169. /*
  170. * Note: tlb->nr may be 0 at this point, so we can't rely on tlb->start_addr and
  171. * tlb->end_addr.
  172. */
  173. ia64_tlb_flush_mmu(tlb, start, end);
  174. /* keep the page table cache within bounds */
  175. check_pgt_cache();
  176. put_cpu_var(mmu_gathers);
  177. }
  178. /*
  179. * Logically, this routine frees PAGE. On MP machines, the actual freeing of the page
  180. * must be delayed until after the TLB has been flushed (see comments at the beginning of
  181. * this file).
  182. */
  183. static inline void
  184. tlb_remove_page (struct mmu_gather *tlb, struct page *page)
  185. {
  186. tlb->need_flush = 1;
  187. if (tlb_fast_mode(tlb)) {
  188. free_page_and_swap_cache(page);
  189. return;
  190. }
  191. tlb->pages[tlb->nr++] = page;
  192. if (tlb->nr >= FREE_PTE_NR)
  193. ia64_tlb_flush_mmu(tlb, tlb->start_addr, tlb->end_addr);
  194. }
  195. /*
  196. * Remove TLB entry for PTE mapped at virtual address ADDRESS. This is called for any
  197. * PTE, not just those pointing to (normal) physical memory.
  198. */
  199. static inline void
  200. __tlb_remove_tlb_entry (struct mmu_gather *tlb, pte_t *ptep, unsigned long address)
  201. {
  202. if (tlb->start_addr == ~0UL)
  203. tlb->start_addr = address;
  204. tlb->end_addr = address + PAGE_SIZE;
  205. }
  206. #define tlb_migrate_finish(mm) platform_tlb_migrate_finish(mm)
  207. #define tlb_start_vma(tlb, vma) do { } while (0)
  208. #define tlb_end_vma(tlb, vma) do { } while (0)
  209. #define tlb_remove_tlb_entry(tlb, ptep, addr) \
  210. do { \
  211. tlb->need_flush = 1; \
  212. __tlb_remove_tlb_entry(tlb, ptep, addr); \
  213. } while (0)
  214. #define pte_free_tlb(tlb, ptep, address) \
  215. do { \
  216. tlb->need_flush = 1; \
  217. __pte_free_tlb(tlb, ptep, address); \
  218. } while (0)
  219. #define pmd_free_tlb(tlb, ptep, address) \
  220. do { \
  221. tlb->need_flush = 1; \
  222. __pmd_free_tlb(tlb, ptep, address); \
  223. } while (0)
  224. #define pud_free_tlb(tlb, pudp, address) \
  225. do { \
  226. tlb->need_flush = 1; \
  227. __pud_free_tlb(tlb, pudp, address); \
  228. } while (0)
  229. #endif /* _ASM_IA64_TLB_H */