mmu_context.h 4.6 KB

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