mmu_context.h 4.8 KB

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