mmu_context.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Switch a MMU context.
  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. * Copyright (C) 1996, 1997, 1998, 1999 by Ralf Baechle
  9. * Copyright (C) 1999 Silicon Graphics, Inc.
  10. */
  11. #ifndef _ASM_MMU_CONTEXT_H
  12. #define _ASM_MMU_CONTEXT_H
  13. #include <linux/errno.h>
  14. #include <linux/sched.h>
  15. #include <linux/smp.h>
  16. #include <linux/slab.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/hazards.h>
  19. #include <asm/tlbflush.h>
  20. #include <asm-generic/mm_hooks.h>
  21. #define TLBMISS_HANDLER_SETUP_PGD(pgd) \
  22. do { \
  23. extern void tlbmiss_handler_setup_pgd(unsigned long); \
  24. tlbmiss_handler_setup_pgd((unsigned long)(pgd)); \
  25. } while (0)
  26. #ifdef CONFIG_MIPS_PGD_C0_CONTEXT
  27. #define TLBMISS_HANDLER_RESTORE() \
  28. write_c0_xcontext((unsigned long) smp_processor_id() << \
  29. SMP_CPUID_REGSHIFT)
  30. #define TLBMISS_HANDLER_SETUP() \
  31. do { \
  32. TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir); \
  33. TLBMISS_HANDLER_RESTORE(); \
  34. } while (0)
  35. #else /* !CONFIG_MIPS_PGD_C0_CONTEXT: using pgd_current*/
  36. /*
  37. * For the fast tlb miss handlers, we keep a per cpu array of pointers
  38. * to the current pgd for each processor. Also, the proc. id is stuffed
  39. * into the context register.
  40. */
  41. extern unsigned long pgd_current[];
  42. #define TLBMISS_HANDLER_RESTORE() \
  43. write_c0_context((unsigned long) smp_processor_id() << \
  44. SMP_CPUID_REGSHIFT)
  45. #define TLBMISS_HANDLER_SETUP() \
  46. TLBMISS_HANDLER_RESTORE(); \
  47. back_to_back_c0_hazard(); \
  48. TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir)
  49. #endif /* CONFIG_MIPS_PGD_C0_CONTEXT*/
  50. #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
  51. #define ASID_INC 0x40
  52. #define ASID_MASK 0xfc0
  53. #elif defined(CONFIG_CPU_R8000)
  54. #define ASID_INC 0x10
  55. #define ASID_MASK 0xff0
  56. #else /* FIXME: not correct for R6000 */
  57. #define ASID_INC 0x1
  58. #define ASID_MASK 0xff
  59. #endif
  60. #define cpu_context(cpu, mm) ((mm)->context.asid[cpu])
  61. #define cpu_asid(cpu, mm) (cpu_context((cpu), (mm)) & ASID_MASK)
  62. #define asid_cache(cpu) (cpu_data[cpu].asid_cache)
  63. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  64. {
  65. }
  66. /*
  67. * All unused by hardware upper bits will be considered
  68. * as a software asid extension.
  69. */
  70. #define ASID_VERSION_MASK ((unsigned long)~(ASID_MASK|(ASID_MASK-1)))
  71. #define ASID_FIRST_VERSION ((unsigned long)(~ASID_VERSION_MASK) + 1)
  72. /* Normal, classic MIPS get_new_mmu_context */
  73. static inline void
  74. get_new_mmu_context(struct mm_struct *mm, unsigned long cpu)
  75. {
  76. extern void kvm_local_flush_tlb_all(void);
  77. unsigned long asid = asid_cache(cpu);
  78. if (! ((asid += ASID_INC) & ASID_MASK) ) {
  79. if (cpu_has_vtag_icache)
  80. flush_icache_all();
  81. #ifdef CONFIG_KVM
  82. kvm_local_flush_tlb_all(); /* start new asid cycle */
  83. #else
  84. local_flush_tlb_all(); /* start new asid cycle */
  85. #endif
  86. if (!asid) /* fix version if needed */
  87. asid = ASID_FIRST_VERSION;
  88. }
  89. cpu_context(cpu, mm) = asid_cache(cpu) = asid;
  90. }
  91. /*
  92. * Initialize the context related info for a new mm_struct
  93. * instance.
  94. */
  95. static inline int
  96. init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  97. {
  98. int i;
  99. for_each_possible_cpu(i)
  100. cpu_context(i, mm) = 0;
  101. return 0;
  102. }
  103. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  104. struct task_struct *tsk)
  105. {
  106. unsigned int cpu = smp_processor_id();
  107. unsigned long flags;
  108. local_irq_save(flags);
  109. /* Check if our ASID is of an older version and thus invalid */
  110. if ((cpu_context(cpu, next) ^ asid_cache(cpu)) & ASID_VERSION_MASK)
  111. get_new_mmu_context(next, cpu);
  112. write_c0_entryhi(cpu_asid(cpu, next));
  113. TLBMISS_HANDLER_SETUP_PGD(next->pgd);
  114. /*
  115. * Mark current->active_mm as not "active" anymore.
  116. * We don't want to mislead possible IPI tlb flush routines.
  117. */
  118. cpumask_clear_cpu(cpu, mm_cpumask(prev));
  119. cpumask_set_cpu(cpu, mm_cpumask(next));
  120. local_irq_restore(flags);
  121. }
  122. /*
  123. * Destroy context related info for an mm_struct that is about
  124. * to be put to rest.
  125. */
  126. static inline void destroy_context(struct mm_struct *mm)
  127. {
  128. }
  129. #define deactivate_mm(tsk, mm) do { } while (0)
  130. /*
  131. * After we have set current->mm to a new value, this activates
  132. * the context for the new mm so we see the new mappings.
  133. */
  134. static inline void
  135. activate_mm(struct mm_struct *prev, struct mm_struct *next)
  136. {
  137. unsigned long flags;
  138. unsigned int cpu = smp_processor_id();
  139. local_irq_save(flags);
  140. /* Unconditionally get a new ASID. */
  141. get_new_mmu_context(next, cpu);
  142. write_c0_entryhi(cpu_asid(cpu, next));
  143. TLBMISS_HANDLER_SETUP_PGD(next->pgd);
  144. /* mark mmu ownership change */
  145. cpumask_clear_cpu(cpu, mm_cpumask(prev));
  146. cpumask_set_cpu(cpu, mm_cpumask(next));
  147. local_irq_restore(flags);
  148. }
  149. /*
  150. * If mm is currently active_mm, we can't really drop it. Instead,
  151. * we will get a new one for it.
  152. */
  153. static inline void
  154. drop_mmu_context(struct mm_struct *mm, unsigned cpu)
  155. {
  156. unsigned long flags;
  157. local_irq_save(flags);
  158. if (cpumask_test_cpu(cpu, mm_cpumask(mm))) {
  159. get_new_mmu_context(mm, cpu);
  160. write_c0_entryhi(cpu_asid(cpu, mm));
  161. } else {
  162. /* will get a new context next time */
  163. cpu_context(cpu, mm) = 0;
  164. }
  165. local_irq_restore(flags);
  166. }
  167. #endif /* _ASM_MMU_CONTEXT_H */