mmu_context.h 3.9 KB

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