mmu_context.h 4.1 KB

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