0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef __ASM_ARM_MMU_CONTEXT_H
0011 #define __ASM_ARM_MMU_CONTEXT_H
0012
0013 #include <linux/compiler.h>
0014 #include <linux/sched.h>
0015 #include <linux/mm_types.h>
0016 #include <linux/preempt.h>
0017
0018 #include <asm/cacheflush.h>
0019 #include <asm/cachetype.h>
0020 #include <asm/proc-fns.h>
0021 #include <asm/smp_plat.h>
0022 #include <asm-generic/mm_hooks.h>
0023
0024 void __check_vmalloc_seq(struct mm_struct *mm);
0025
0026 #ifdef CONFIG_MMU
0027 static inline void check_vmalloc_seq(struct mm_struct *mm)
0028 {
0029 if (!IS_ENABLED(CONFIG_ARM_LPAE) &&
0030 unlikely(atomic_read(&mm->context.vmalloc_seq) !=
0031 atomic_read(&init_mm.context.vmalloc_seq)))
0032 __check_vmalloc_seq(mm);
0033 }
0034 #endif
0035
0036 #ifdef CONFIG_CPU_HAS_ASID
0037
0038 void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk);
0039
0040 #define init_new_context init_new_context
0041 static inline int
0042 init_new_context(struct task_struct *tsk, struct mm_struct *mm)
0043 {
0044 atomic64_set(&mm->context.id, 0);
0045 return 0;
0046 }
0047
0048 #ifdef CONFIG_ARM_ERRATA_798181
0049 void a15_erratum_get_cpumask(int this_cpu, struct mm_struct *mm,
0050 cpumask_t *mask);
0051 #else
0052 static inline void a15_erratum_get_cpumask(int this_cpu, struct mm_struct *mm,
0053 cpumask_t *mask)
0054 {
0055 }
0056 #endif
0057
0058 #else
0059
0060 #ifdef CONFIG_MMU
0061
0062 static inline void check_and_switch_context(struct mm_struct *mm,
0063 struct task_struct *tsk)
0064 {
0065 check_vmalloc_seq(mm);
0066
0067 if (irqs_disabled())
0068
0069
0070
0071
0072
0073
0074
0075 mm->context.switch_pending = 1;
0076 else
0077 cpu_switch_mm(mm->pgd, mm);
0078 }
0079
0080 #ifndef MODULE
0081 #define finish_arch_post_lock_switch \
0082 finish_arch_post_lock_switch
0083 static inline void finish_arch_post_lock_switch(void)
0084 {
0085 struct mm_struct *mm = current->mm;
0086
0087 if (mm && mm->context.switch_pending) {
0088
0089
0090
0091
0092
0093
0094 preempt_disable();
0095 if (mm->context.switch_pending) {
0096 mm->context.switch_pending = 0;
0097 cpu_switch_mm(mm->pgd, mm);
0098 }
0099 preempt_enable_no_resched();
0100 }
0101 }
0102 #endif
0103
0104 #endif
0105
0106 #endif
0107
0108 #define activate_mm(prev,next) switch_mm(prev, next, NULL)
0109
0110
0111
0112
0113
0114
0115
0116 static inline void
0117 switch_mm(struct mm_struct *prev, struct mm_struct *next,
0118 struct task_struct *tsk)
0119 {
0120 #ifdef CONFIG_MMU
0121 unsigned int cpu = smp_processor_id();
0122
0123
0124
0125
0126
0127
0128 if (cache_ops_need_broadcast() &&
0129 !cpumask_empty(mm_cpumask(next)) &&
0130 !cpumask_test_cpu(cpu, mm_cpumask(next)))
0131 __flush_icache_all();
0132
0133 if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) || prev != next) {
0134 check_and_switch_context(next, tsk);
0135 if (cache_is_vivt())
0136 cpumask_clear_cpu(cpu, mm_cpumask(prev));
0137 }
0138 #endif
0139 }
0140
0141 #ifdef CONFIG_VMAP_STACK
0142 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
0143 {
0144 if (mm != &init_mm)
0145 check_vmalloc_seq(mm);
0146 }
0147 #define enter_lazy_tlb enter_lazy_tlb
0148 #endif
0149
0150 #include <asm-generic/mmu_context.h>
0151
0152 #endif