blob: c28f32a45af5d9003de5cb36f4bc0d5a35722c57 [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
Martin Schwidefskybeef5602014-04-14 15:11:26 +020034static inline void set_user_asce(struct mm_struct *mm)
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);
Martin Schwidefsky6252d702008-02-09 18:24:37 +010039 set_fs(current->thread.mm_segment);
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020040 set_cpu_flag(CIF_ASCE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
Martin Schwidefskybeef5602014-04-14 15:11:26 +020043static inline void clear_user_asce(void)
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020044{
45 S390_lowcore.user_asce = S390_lowcore.kernel_asce;
Heiko Carstens457f2182014-03-21 10:42:25 +010046
Martin Schwidefskybeef5602014-04-14 15:11:26 +020047 __ctl_load(S390_lowcore.user_asce, 1, 1);
Heiko Carstens457f2182014-03-21 10:42:25 +010048 __ctl_load(S390_lowcore.user_asce, 7, 7);
49}
50
Martin Schwidefskybeef5602014-04-14 15:11:26 +020051static inline void load_kernel_asce(void)
Heiko Carstens457f2182014-03-21 10:42:25 +010052{
53 unsigned long asce;
54
55 __ctl_store(asce, 1, 1);
56 if (asce != S390_lowcore.kernel_asce)
57 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020058 set_cpu_flag(CIF_ASCE);
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020059}
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
Gerald Schaeferc1821c22007-02-05 21:18:17 +010062 struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020064 int cpu = smp_processor_id();
65
66 if (prev == next)
67 return;
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020068 if (MACHINE_HAS_TLB_LC)
69 cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
Martin Schwidefskybeef5602014-04-14 15:11:26 +020070 /* Clear old ASCE by loading the kernel ASCE. */
71 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
72 __ctl_load(S390_lowcore.kernel_asce, 7, 7);
73 /* Delay loading of the new ASCE to control registers CR1 & CR7 */
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020074 set_cpu_flag(CIF_ASCE);
Martin Schwidefskybeef5602014-04-14 15:11:26 +020075 atomic_inc(&next->context.attach_count);
Martin Schwidefsky050eef32010-08-24 09:26:21 +020076 atomic_dec(&prev->context.attach_count);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020077 if (MACHINE_HAS_TLB_LC)
78 cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020079}
80
81#define finish_arch_post_lock_switch finish_arch_post_lock_switch
82static inline void finish_arch_post_lock_switch(void)
83{
84 struct task_struct *tsk = current;
85 struct mm_struct *mm = tsk->mm;
86
Martin Schwidefskybeef5602014-04-14 15:11:26 +020087 if (!mm)
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020088 return;
89 preempt_disable();
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020090 while (atomic_read(&mm->context.attach_count) >> 16)
91 cpu_relax();
92
93 cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
Martin Schwidefskybeef5602014-04-14 15:11:26 +020094 set_user_asce(mm);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020095 if (mm->context.flush_mm)
96 __tlb_flush_mm(mm);
97 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
Martin Schwidefsky3610cce2007-10-22 12:52:47 +0200100#define enter_lazy_tlb(mm,tsk) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define deactivate_mm(tsk,mm) do { } while (0)
102
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800103static inline void activate_mm(struct mm_struct *prev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 struct mm_struct *next)
105{
Martin Schwidefskybeef5602014-04-14 15:11:26 +0200106 switch_mm(prev, next, current);
107 cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
108 set_user_asce(next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Martin Schwidefsky0f6f2812012-07-26 08:53:06 +0200111static inline void arch_dup_mmap(struct mm_struct *oldmm,
112 struct mm_struct *mm)
113{
114#ifdef CONFIG_64BIT
115 if (oldmm->context.asce_limit < mm->context.asce_limit)
116 crst_table_downgrade(mm, oldmm->context.asce_limit);
117#endif
118}
119
120static inline void arch_exit_mmap(struct mm_struct *mm)
121{
122}
123
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100124#endif /* __S390_MMU_CONTEXT_H */