mmu_context.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * arch/arm/include/asm/mmu_context.h
  3. *
  4. * Copyright (C) 1996 Russell King.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Changelog:
  11. * 27-06-1996 RMK Created
  12. */
  13. #ifndef __ASM_ARM_MMU_CONTEXT_H
  14. #define __ASM_ARM_MMU_CONTEXT_H
  15. #include <linux/compiler.h>
  16. #include <linux/sched.h>
  17. #include <linux/preempt.h>
  18. #include <asm/cacheflush.h>
  19. #include <asm/cachetype.h>
  20. #include <asm/proc-fns.h>
  21. #include <asm/smp_plat.h>
  22. #include <asm-generic/mm_hooks.h>
  23. void __check_vmalloc_seq(struct mm_struct *mm);
  24. #ifdef CONFIG_CPU_HAS_ASID
  25. void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk);
  26. static inline int
  27. init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  28. {
  29. atomic64_set(&mm->context.id, 0);
  30. return 0;
  31. }
  32. #ifdef CONFIG_ARM_ERRATA_798181
  33. void a15_erratum_get_cpumask(int this_cpu, struct mm_struct *mm,
  34. cpumask_t *mask);
  35. #else /* !CONFIG_ARM_ERRATA_798181 */
  36. static inline void a15_erratum_get_cpumask(int this_cpu, struct mm_struct *mm,
  37. cpumask_t *mask)
  38. {
  39. }
  40. #endif /* CONFIG_ARM_ERRATA_798181 */
  41. #else /* !CONFIG_CPU_HAS_ASID */
  42. #ifdef CONFIG_MMU
  43. static inline void check_and_switch_context(struct mm_struct *mm,
  44. struct task_struct *tsk)
  45. {
  46. if (unlikely(mm->context.vmalloc_seq != init_mm.context.vmalloc_seq))
  47. __check_vmalloc_seq(mm);
  48. if (irqs_disabled())
  49. /*
  50. * cpu_switch_mm() needs to flush the VIVT caches. To avoid
  51. * high interrupt latencies, defer the call and continue
  52. * running with the old mm. Since we only support UP systems
  53. * on non-ASID CPUs, the old mm will remain valid until the
  54. * finish_arch_post_lock_switch() call.
  55. */
  56. mm->context.switch_pending = 1;
  57. else
  58. cpu_switch_mm(mm->pgd, mm);
  59. }
  60. #ifndef MODULE
  61. #define finish_arch_post_lock_switch \
  62. finish_arch_post_lock_switch
  63. static inline void finish_arch_post_lock_switch(void)
  64. {
  65. struct mm_struct *mm = current->mm;
  66. if (mm && mm->context.switch_pending) {
  67. /*
  68. * Preemption must be disabled during cpu_switch_mm() as we
  69. * have some stateful cache flush implementations. Check
  70. * switch_pending again in case we were preempted and the
  71. * switch to this mm was already done.
  72. */
  73. preempt_disable();
  74. if (mm->context.switch_pending) {
  75. mm->context.switch_pending = 0;
  76. cpu_switch_mm(mm->pgd, mm);
  77. }
  78. preempt_enable_no_resched();
  79. }
  80. }
  81. #endif /* !MODULE */
  82. #endif /* CONFIG_MMU */
  83. static inline int
  84. init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  85. {
  86. return 0;
  87. }
  88. #endif /* CONFIG_CPU_HAS_ASID */
  89. #define destroy_context(mm) do { } while(0)
  90. #define activate_mm(prev,next) switch_mm(prev, next, NULL)
  91. /*
  92. * This is called when "tsk" is about to enter lazy TLB mode.
  93. *
  94. * mm: describes the currently active mm context
  95. * tsk: task which is entering lazy tlb
  96. * cpu: cpu number which is entering lazy tlb
  97. *
  98. * tsk->mm will be NULL
  99. */
  100. static inline void
  101. enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  102. {
  103. }
  104. /*
  105. * This is the actual mm switch as far as the scheduler
  106. * is concerned. No registers are touched. We avoid
  107. * calling the CPU specific function when the mm hasn't
  108. * actually changed.
  109. */
  110. static inline void
  111. switch_mm(struct mm_struct *prev, struct mm_struct *next,
  112. struct task_struct *tsk)
  113. {
  114. #ifdef CONFIG_MMU
  115. unsigned int cpu = smp_processor_id();
  116. /*
  117. * __sync_icache_dcache doesn't broadcast the I-cache invalidation,
  118. * so check for possible thread migration and invalidate the I-cache
  119. * if we're new to this CPU.
  120. */
  121. if (cache_ops_need_broadcast() &&
  122. !cpumask_empty(mm_cpumask(next)) &&
  123. !cpumask_test_cpu(cpu, mm_cpumask(next)))
  124. __flush_icache_all();
  125. if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) || prev != next) {
  126. check_and_switch_context(next, tsk);
  127. if (cache_is_vivt())
  128. cpumask_clear_cpu(cpu, mm_cpumask(prev));
  129. }
  130. #endif
  131. }
  132. #define deactivate_mm(tsk,mm) do { } while (0)
  133. #endif