blob: d42fb1b728d89c1768ad3ccefd9fb2fd82c20306 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * S390 version
3 *
4 * Derived from "include/asm-i386/mmu_context.h"
5 */
6
7#ifndef __S390_MMU_CONTEXT_H
8#define __S390_MMU_CONTEXT_H
9
Gerald Schaeferc1821c22007-02-05 21:18:17 +010010#include <asm/pgalloc.h>
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010011#include <asm/uaccess.h>
Martin Schwidefsky050eef32010-08-24 09:26:21 +020012#include <asm/tlbflush.h>
David Howellsa0616cd2012-03-28 18:30:02 +010013#include <asm/ctl_reg.h>
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +020014
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010015static inline int init_new_context(struct task_struct *tsk,
16 struct mm_struct *mm)
17{
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020018 cpumask_clear(&mm->context.cpu_attach_mask);
Martin Schwidefsky050eef32010-08-24 09:26:21 +020019 atomic_set(&mm->context.attach_count, 0);
20 mm->context.flush_mm = 0;
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010021 mm->context.asce_bits = _ASCE_TABLE_LENGTH | _ASCE_USER_BITS;
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010022#ifdef CONFIG_64BIT
Martin Schwidefsky6252d702008-02-09 18:24:37 +010023 mm->context.asce_bits |= _ASCE_TYPE_REGION3;
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010024#endif
Martin Schwidefsky3eabaee2013-07-26 15:04:02 +020025 mm->context.has_pgste = 0;
Dominik Dingel693ffc02014-01-14 18:11:14 +010026 mm->context.use_skey = 0;
Martin Schwidefsky6252d702008-02-09 18:24:37 +010027 mm->context.asce_limit = STACK_TOP_MAX;
28 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010029 return 0;
30}
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#define destroy_context(mm) do { } while (0)
33
Heiko Carstens457f2182014-03-21 10:42:25 +010034static inline void update_user_asce(struct mm_struct *mm, int load_primary)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010036 pgd_t *pgd = mm->pgd;
37
38 S390_lowcore.user_asce = mm->context.asce_bits | __pa(pgd);
Heiko Carstens457f2182014-03-21 10:42:25 +010039 if (load_primary)
40 __ctl_load(S390_lowcore.user_asce, 1, 1);
Martin Schwidefsky6252d702008-02-09 18:24:37 +010041 set_fs(current->thread.mm_segment);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
43
Heiko Carstens457f2182014-03-21 10:42:25 +010044static inline void clear_user_asce(struct mm_struct *mm, int load_primary)
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020045{
46 S390_lowcore.user_asce = S390_lowcore.kernel_asce;
Heiko Carstens457f2182014-03-21 10:42:25 +010047
48 if (load_primary)
49 __ctl_load(S390_lowcore.user_asce, 1, 1);
50 __ctl_load(S390_lowcore.user_asce, 7, 7);
51}
52
53static inline void update_primary_asce(struct task_struct *tsk)
54{
55 unsigned long asce;
56
57 __ctl_store(asce, 1, 1);
58 if (asce != S390_lowcore.kernel_asce)
59 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
60 set_tsk_thread_flag(tsk, TIF_ASCE);
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020061}
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
Gerald Schaeferc1821c22007-02-05 21:18:17 +010064 struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020066 int cpu = smp_processor_id();
67
Heiko Carstens457f2182014-03-21 10:42:25 +010068 update_primary_asce(tsk);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020069 if (prev == next)
70 return;
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020071 if (MACHINE_HAS_TLB_LC)
72 cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020073 if (atomic_inc_return(&next->context.attach_count) >> 16) {
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020074 /* Delay update_user_asce until all TLB flushes are done. */
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020075 set_tsk_thread_flag(tsk, TIF_TLB_WAIT);
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020076 /* Clear old ASCE by loading the kernel ASCE. */
Heiko Carstens457f2182014-03-21 10:42:25 +010077 clear_user_asce(next, 0);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020078 } else {
79 cpumask_set_cpu(cpu, mm_cpumask(next));
Heiko Carstens457f2182014-03-21 10:42:25 +010080 update_user_asce(next, 0);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020081 if (next->context.flush_mm)
82 /* Flush pending TLBs */
83 __tlb_flush_mm(next);
84 }
Martin Schwidefsky050eef32010-08-24 09:26:21 +020085 atomic_dec(&prev->context.attach_count);
86 WARN_ON(atomic_read(&prev->context.attach_count) < 0);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020087 if (MACHINE_HAS_TLB_LC)
88 cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020089}
90
91#define finish_arch_post_lock_switch finish_arch_post_lock_switch
92static inline void finish_arch_post_lock_switch(void)
93{
94 struct task_struct *tsk = current;
95 struct mm_struct *mm = tsk->mm;
96
97 if (!test_tsk_thread_flag(tsk, TIF_TLB_WAIT))
98 return;
99 preempt_disable();
100 clear_tsk_thread_flag(tsk, TIF_TLB_WAIT);
101 while (atomic_read(&mm->context.attach_count) >> 16)
102 cpu_relax();
103
104 cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
Heiko Carstens457f2182014-03-21 10:42:25 +0100105 update_user_asce(mm, 0);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +0200106 if (mm->context.flush_mm)
107 __tlb_flush_mm(mm);
108 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Martin Schwidefsky3610cce2007-10-22 12:52:47 +0200111#define enter_lazy_tlb(mm,tsk) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#define deactivate_mm(tsk,mm) do { } while (0)
113
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800114static inline void activate_mm(struct mm_struct *prev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 struct mm_struct *next)
116{
117 switch_mm(prev, next, current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
Martin Schwidefsky0f6f2812012-07-26 08:53:06 +0200120static inline void arch_dup_mmap(struct mm_struct *oldmm,
121 struct mm_struct *mm)
122{
123#ifdef CONFIG_64BIT
124 if (oldmm->context.asce_limit < mm->context.asce_limit)
125 crst_table_downgrade(mm, oldmm->context.asce_limit);
126#endif
127}
128
129static inline void arch_exit_mmap(struct mm_struct *mm)
130{
131}
132
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100133#endif /* __S390_MMU_CONTEXT_H */