blob: 7abf318b1522726eb8858226d3f59b211542b799 [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 Schwidefsky050eef32010-08-24 09:26:21 +020018 atomic_set(&mm->context.attach_count, 0);
19 mm->context.flush_mm = 0;
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010020 mm->context.asce_bits = _ASCE_TABLE_LENGTH | _ASCE_USER_BITS;
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010021#ifdef CONFIG_64BIT
Martin Schwidefsky6252d702008-02-09 18:24:37 +010022 mm->context.asce_bits |= _ASCE_TYPE_REGION3;
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010023#endif
Martin Schwidefsky3eabaee2013-07-26 15:04:02 +020024 mm->context.has_pgste = 0;
Martin Schwidefsky6252d702008-02-09 18:24:37 +010025 mm->context.asce_limit = STACK_TOP_MAX;
26 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010027 return 0;
28}
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#define destroy_context(mm) do { } while (0)
31
Heiko Carstensf4815ac2012-05-23 16:24:51 +020032#ifndef CONFIG_64BIT
Gerald Schaeferc1821c22007-02-05 21:18:17 +010033#define LCTL_OPCODE "lctl"
Gerald Schaeferc1821c22007-02-05 21:18:17 +010034#else
35#define LCTL_OPCODE "lctlg"
Gerald Schaeferc1821c22007-02-05 21:18:17 +010036#endif
37
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020038static inline void update_user_asce(struct mm_struct *mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010040 pgd_t *pgd = mm->pgd;
41
42 S390_lowcore.user_asce = mm->context.asce_bits | __pa(pgd);
Martin Schwidefskye258d712013-09-24 09:14:56 +020043 /* Load primary space page table origin. */
44 asm volatile(LCTL_OPCODE" 1,1,%0\n" : : "m" (S390_lowcore.user_asce));
Martin Schwidefsky6252d702008-02-09 18:24:37 +010045 set_fs(current->thread.mm_segment);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020048static inline void clear_user_asce(struct mm_struct *mm)
49{
50 S390_lowcore.user_asce = S390_lowcore.kernel_asce;
51 asm volatile(LCTL_OPCODE" 1,1,%0\n" : : "m" (S390_lowcore.user_asce));
52 asm volatile(LCTL_OPCODE" 7,7,%0\n" : : "m" (S390_lowcore.user_asce));
53}
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
Gerald Schaeferc1821c22007-02-05 21:18:17 +010056 struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020058 int cpu = smp_processor_id();
59
60 if (prev == next)
61 return;
62 if (atomic_inc_return(&next->context.attach_count) >> 16) {
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020063 /* Delay update_user_asce until all TLB flushes are done. */
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020064 set_tsk_thread_flag(tsk, TIF_TLB_WAIT);
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020065 /* Clear old ASCE by loading the kernel ASCE. */
66 clear_user_asce(next);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020067 } else {
68 cpumask_set_cpu(cpu, mm_cpumask(next));
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020069 update_user_asce(next);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020070 if (next->context.flush_mm)
71 /* Flush pending TLBs */
72 __tlb_flush_mm(next);
73 }
Martin Schwidefsky050eef32010-08-24 09:26:21 +020074 atomic_dec(&prev->context.attach_count);
75 WARN_ON(atomic_read(&prev->context.attach_count) < 0);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020076}
77
78#define finish_arch_post_lock_switch finish_arch_post_lock_switch
79static inline void finish_arch_post_lock_switch(void)
80{
81 struct task_struct *tsk = current;
82 struct mm_struct *mm = tsk->mm;
83
84 if (!test_tsk_thread_flag(tsk, TIF_TLB_WAIT))
85 return;
86 preempt_disable();
87 clear_tsk_thread_flag(tsk, TIF_TLB_WAIT);
88 while (atomic_read(&mm->context.attach_count) >> 16)
89 cpu_relax();
90
91 cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020092 update_user_asce(mm);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020093 if (mm->context.flush_mm)
94 __tlb_flush_mm(mm);
95 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020098#define enter_lazy_tlb(mm,tsk) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#define deactivate_mm(tsk,mm) do { } while (0)
100
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800101static inline void activate_mm(struct mm_struct *prev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 struct mm_struct *next)
103{
104 switch_mm(prev, next, current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
Martin Schwidefsky0f6f2812012-07-26 08:53:06 +0200107static inline void arch_dup_mmap(struct mm_struct *oldmm,
108 struct mm_struct *mm)
109{
110#ifdef CONFIG_64BIT
111 if (oldmm->context.asce_limit < mm->context.asce_limit)
112 crst_table_downgrade(mm, oldmm->context.asce_limit);
113#endif
114}
115
116static inline void arch_exit_mmap(struct mm_struct *mm)
117{
118}
119
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100120#endif /* __S390_MMU_CONTEXT_H */