mmu_context.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #ifndef __ASM_SH64_MMU_CONTEXT_H
  2. #define __ASM_SH64_MMU_CONTEXT_H
  3. /*
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * include/asm-sh64/mmu_context.h
  9. *
  10. * Copyright (C) 2000, 2001 Paolo Alberelli
  11. * Copyright (C) 2003 Paul Mundt
  12. *
  13. * ASID handling idea taken from MIPS implementation.
  14. *
  15. */
  16. #ifndef __ASSEMBLY__
  17. /*
  18. * Cache of MMU context last used.
  19. *
  20. * The MMU "context" consists of two things:
  21. * (a) TLB cache version (or cycle, top 24 bits of mmu_context_cache)
  22. * (b) ASID (Address Space IDentifier, bottom 8 bits of mmu_context_cache)
  23. */
  24. extern unsigned long mmu_context_cache;
  25. #include <linux/config.h>
  26. #include <asm/page.h>
  27. /* Current mm's pgd */
  28. extern pgd_t *mmu_pdtp_cache;
  29. #define SR_ASID_MASK 0xffffffffff00ffffULL
  30. #define SR_ASID_SHIFT 16
  31. #define MMU_CONTEXT_ASID_MASK 0x000000ff
  32. #define MMU_CONTEXT_VERSION_MASK 0xffffff00
  33. #define MMU_CONTEXT_FIRST_VERSION 0x00000100
  34. #define NO_CONTEXT 0
  35. /* ASID is 8-bit value, so it can't be 0x100 */
  36. #define MMU_NO_ASID 0x100
  37. /*
  38. * Virtual Page Number mask
  39. */
  40. #define MMU_VPN_MASK 0xfffff000
  41. static inline void
  42. get_new_mmu_context(struct mm_struct *mm)
  43. {
  44. extern void flush_tlb_all(void);
  45. extern void flush_cache_all(void);
  46. unsigned long mc = ++mmu_context_cache;
  47. if (!(mc & MMU_CONTEXT_ASID_MASK)) {
  48. /* We exhaust ASID of this version.
  49. Flush all TLB and start new cycle. */
  50. flush_tlb_all();
  51. /* We have to flush all caches as ASIDs are
  52. used in cache */
  53. flush_cache_all();
  54. /* Fix version if needed.
  55. Note that we avoid version #0/asid #0 to distingush NO_CONTEXT. */
  56. if (!mc)
  57. mmu_context_cache = mc = MMU_CONTEXT_FIRST_VERSION;
  58. }
  59. mm->context = mc;
  60. }
  61. /*
  62. * Get MMU context if needed.
  63. */
  64. static __inline__ void
  65. get_mmu_context(struct mm_struct *mm)
  66. {
  67. if (mm) {
  68. unsigned long mc = mmu_context_cache;
  69. /* Check if we have old version of context.
  70. If it's old, we need to get new context with new version. */
  71. if ((mm->context ^ mc) & MMU_CONTEXT_VERSION_MASK)
  72. get_new_mmu_context(mm);
  73. }
  74. }
  75. /*
  76. * Initialize the context related info for a new mm_struct
  77. * instance.
  78. */
  79. static inline int init_new_context(struct task_struct *tsk,
  80. struct mm_struct *mm)
  81. {
  82. mm->context = NO_CONTEXT;
  83. return 0;
  84. }
  85. /*
  86. * Destroy context related info for an mm_struct that is about
  87. * to be put to rest.
  88. */
  89. static inline void destroy_context(struct mm_struct *mm)
  90. {
  91. extern void flush_tlb_mm(struct mm_struct *mm);
  92. /* Well, at least free TLB entries */
  93. flush_tlb_mm(mm);
  94. }
  95. #endif /* __ASSEMBLY__ */
  96. /* Common defines */
  97. #define TLB_STEP 0x00000010
  98. #define TLB_PTEH 0x00000000
  99. #define TLB_PTEL 0x00000008
  100. /* PTEH defines */
  101. #define PTEH_ASID_SHIFT 2
  102. #define PTEH_VALID 0x0000000000000001
  103. #define PTEH_SHARED 0x0000000000000002
  104. #define PTEH_MATCH_ASID 0x00000000000003ff
  105. #ifndef __ASSEMBLY__
  106. /* This has to be a common function because the next location to fill
  107. * information is shared. */
  108. extern void __do_tlb_refill(unsigned long address, unsigned long long is_text_not_data, pte_t *pte);
  109. /* Profiling counter. */
  110. #ifdef CONFIG_SH64_PROC_TLB
  111. extern unsigned long long calls_to_do_fast_page_fault;
  112. #endif
  113. static inline unsigned long get_asid(void)
  114. {
  115. unsigned long long sr;
  116. asm volatile ("getcon " __SR ", %0\n\t"
  117. : "=r" (sr));
  118. sr = (sr >> SR_ASID_SHIFT) & MMU_CONTEXT_ASID_MASK;
  119. return (unsigned long) sr;
  120. }
  121. /* Set ASID into SR */
  122. static inline void set_asid(unsigned long asid)
  123. {
  124. unsigned long long sr, pc;
  125. asm volatile ("getcon " __SR ", %0" : "=r" (sr));
  126. sr = (sr & SR_ASID_MASK) | (asid << SR_ASID_SHIFT);
  127. /*
  128. * It is possible that this function may be inlined and so to avoid
  129. * the assembler reporting duplicate symbols we make use of the gas trick
  130. * of generating symbols using numerics and forward reference.
  131. */
  132. asm volatile ("movi 1, %1\n\t"
  133. "shlli %1, 28, %1\n\t"
  134. "or %0, %1, %1\n\t"
  135. "putcon %1, " __SR "\n\t"
  136. "putcon %0, " __SSR "\n\t"
  137. "movi 1f, %1\n\t"
  138. "ori %1, 1 , %1\n\t"
  139. "putcon %1, " __SPC "\n\t"
  140. "rte\n"
  141. "1:\n\t"
  142. : "=r" (sr), "=r" (pc) : "0" (sr));
  143. }
  144. /*
  145. * After we have set current->mm to a new value, this activates
  146. * the context for the new mm so we see the new mappings.
  147. */
  148. static __inline__ void activate_context(struct mm_struct *mm)
  149. {
  150. get_mmu_context(mm);
  151. set_asid(mm->context & MMU_CONTEXT_ASID_MASK);
  152. }
  153. static __inline__ void switch_mm(struct mm_struct *prev,
  154. struct mm_struct *next,
  155. struct task_struct *tsk)
  156. {
  157. if (prev != next) {
  158. mmu_pdtp_cache = next->pgd;
  159. activate_context(next);
  160. }
  161. }
  162. #define deactivate_mm(tsk,mm) do { } while (0)
  163. #define activate_mm(prev, next) \
  164. switch_mm((prev),(next),NULL)
  165. static inline void
  166. enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  167. {
  168. }
  169. #endif /* __ASSEMBLY__ */
  170. #endif /* __ASM_SH64_MMU_CONTEXT_H */