mmu_context.h 3.7 KB

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