mmu_context.h 4.1 KB

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