mmu_context.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #ifndef _ASM_M32R_MMU_CONTEXT_H
  2. #define _ASM_M32R_MMU_CONTEXT_H
  3. #ifdef __KERNEL__
  4. #include <asm/m32r.h>
  5. #define MMU_CONTEXT_ASID_MASK (0x000000FF)
  6. #define MMU_CONTEXT_VERSION_MASK (0xFFFFFF00)
  7. #define MMU_CONTEXT_FIRST_VERSION (0x00000100)
  8. #define NO_CONTEXT (0x00000000)
  9. #ifndef __ASSEMBLY__
  10. #include <linux/atomic.h>
  11. #include <asm/pgalloc.h>
  12. #include <asm/mmu.h>
  13. #include <asm/tlbflush.h>
  14. #include <asm-generic/mm_hooks.h>
  15. /*
  16. * Cache of MMU context last used.
  17. */
  18. #ifndef CONFIG_SMP
  19. extern unsigned long mmu_context_cache_dat;
  20. #define mmu_context_cache mmu_context_cache_dat
  21. #define mm_context(mm) mm->context
  22. #else /* not CONFIG_SMP */
  23. extern unsigned long mmu_context_cache_dat[];
  24. #define mmu_context_cache mmu_context_cache_dat[smp_processor_id()]
  25. #define mm_context(mm) mm->context[smp_processor_id()]
  26. #endif /* not CONFIG_SMP */
  27. #define set_tlb_tag(entry, tag) (*entry = (tag & PAGE_MASK)|get_asid())
  28. #define set_tlb_data(entry, data) (*entry = (data | _PAGE_PRESENT))
  29. #ifdef CONFIG_MMU
  30. #define enter_lazy_tlb(mm, tsk) do { } while (0)
  31. static inline void get_new_mmu_context(struct mm_struct *mm)
  32. {
  33. unsigned long mc = ++mmu_context_cache;
  34. if (!(mc & MMU_CONTEXT_ASID_MASK)) {
  35. /* We exhaust ASID of this version.
  36. Flush all TLB and start new cycle. */
  37. local_flush_tlb_all();
  38. /* Fix version if needed.
  39. Note that we avoid version #0 to distinguish NO_CONTEXT. */
  40. if (!mc)
  41. mmu_context_cache = mc = MMU_CONTEXT_FIRST_VERSION;
  42. }
  43. mm_context(mm) = mc;
  44. }
  45. /*
  46. * Get MMU context if needed.
  47. */
  48. static inline void get_mmu_context(struct mm_struct *mm)
  49. {
  50. if (mm) {
  51. unsigned long mc = mmu_context_cache;
  52. /* Check if we have old version of context.
  53. If it's old, we need to get new context with new version. */
  54. if ((mm_context(mm) ^ mc) & MMU_CONTEXT_VERSION_MASK)
  55. get_new_mmu_context(mm);
  56. }
  57. }
  58. /*
  59. * Initialize the context related info for a new mm_struct
  60. * instance.
  61. */
  62. static inline int init_new_context(struct task_struct *tsk,
  63. struct mm_struct *mm)
  64. {
  65. #ifndef CONFIG_SMP
  66. mm->context = NO_CONTEXT;
  67. #else /* CONFIG_SMP */
  68. int num_cpus = num_online_cpus();
  69. int i;
  70. for (i = 0 ; i < num_cpus ; i++)
  71. mm->context[i] = NO_CONTEXT;
  72. #endif /* CONFIG_SMP */
  73. return 0;
  74. }
  75. /*
  76. * Destroy context related info for an mm_struct that is about
  77. * to be put to rest.
  78. */
  79. #define destroy_context(mm) do { } while (0)
  80. static inline void set_asid(unsigned long asid)
  81. {
  82. *(volatile unsigned long *)MASID = (asid & MMU_CONTEXT_ASID_MASK);
  83. }
  84. static inline unsigned long get_asid(void)
  85. {
  86. unsigned long asid;
  87. asid = *(volatile long *)MASID;
  88. asid &= MMU_CONTEXT_ASID_MASK;
  89. return asid;
  90. }
  91. /*
  92. * After we have set current->mm to a new value, this activates
  93. * the context for the new mm so we see the new mappings.
  94. */
  95. static inline void activate_context(struct mm_struct *mm)
  96. {
  97. get_mmu_context(mm);
  98. set_asid(mm_context(mm) & MMU_CONTEXT_ASID_MASK);
  99. }
  100. static inline void switch_mm(struct mm_struct *prev,
  101. struct mm_struct *next, struct task_struct *tsk)
  102. {
  103. #ifdef CONFIG_SMP
  104. int cpu = smp_processor_id();
  105. #endif /* CONFIG_SMP */
  106. if (prev != next) {
  107. #ifdef CONFIG_SMP
  108. cpumask_set_cpu(cpu, mm_cpumask(next));
  109. #endif /* CONFIG_SMP */
  110. /* Set MPTB = next->pgd */
  111. *(volatile unsigned long *)MPTB = (unsigned long)next->pgd;
  112. activate_context(next);
  113. }
  114. #ifdef CONFIG_SMP
  115. else
  116. if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)))
  117. activate_context(next);
  118. #endif /* CONFIG_SMP */
  119. }
  120. #define deactivate_mm(tsk, mm) do { } while (0)
  121. #define activate_mm(prev, next) \
  122. switch_mm((prev), (next), NULL)
  123. #else /* not CONFIG_MMU */
  124. #define get_mmu_context(mm) do { } while (0)
  125. #define init_new_context(tsk,mm) (0)
  126. #define destroy_context(mm) do { } while (0)
  127. #define set_asid(asid) do { } while (0)
  128. #define get_asid() (0)
  129. #define activate_context(mm) do { } while (0)
  130. #define switch_mm(prev,next,tsk) do { } while (0)
  131. #define deactivate_mm(mm,tsk) do { } while (0)
  132. #define activate_mm(prev,next) do { } while (0)
  133. #define enter_lazy_tlb(mm,tsk) do { } while (0)
  134. #endif /* not CONFIG_MMU */
  135. #endif /* not __ASSEMBLY__ */
  136. #endif /* __KERNEL__ */
  137. #endif /* _ASM_M32R_MMU_CONTEXT_H */