blob: 5d09e405c54d504a8e3a243b54155d91eb8e18db [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * include/asm-s390/mmu_context.h
3 *
4 * S390 version
5 *
6 * Derived from "include/asm-i386/mmu_context.h"
7 */
8
9#ifndef __S390_MMU_CONTEXT_H
10#define __S390_MMU_CONTEXT_H
11
Gerald Schaeferc1821c22007-02-05 21:18:17 +010012#include <asm/pgalloc.h>
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010013#include <asm/uaccess.h>
Martin Schwidefsky050eef32010-08-24 09:26:21 +020014#include <asm/tlbflush.h>
David Howellsa0616cd2012-03-28 18:30:02 +010015#include <asm/ctl_reg.h>
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +020016#include <asm-generic/mm_hooks.h>
17
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010018static inline int init_new_context(struct task_struct *tsk,
19 struct mm_struct *mm)
20{
Martin Schwidefsky050eef32010-08-24 09:26:21 +020021 atomic_set(&mm->context.attach_count, 0);
22 mm->context.flush_mm = 0;
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010023 mm->context.asce_bits = _ASCE_TABLE_LENGTH | _ASCE_USER_BITS;
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010024#ifdef CONFIG_64BIT
Martin Schwidefsky6252d702008-02-09 18:24:37 +010025 mm->context.asce_bits |= _ASCE_TYPE_REGION3;
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010026#endif
Martin Schwidefskybadb8bb2011-05-10 17:13:43 +020027 if (current->mm && current->mm->context.alloc_pgste) {
Christian Borntraeger250cf772008-10-28 11:10:15 +010028 /*
29 * alloc_pgste indicates, that any NEW context will be created
30 * with extended page tables. The old context is unchanged. The
31 * page table allocation and the page table operations will
32 * look at has_pgste to distinguish normal and extended page
33 * tables. The only way to create extended page tables is to
34 * set alloc_pgste and then create a new context (e.g. dup_mm).
35 * The page table allocation is called after init_new_context
36 * and if has_pgste is set, it will create extended page
37 * tables.
38 */
Christian Borntraeger250cf772008-10-28 11:10:15 +010039 mm->context.has_pgste = 1;
40 mm->context.alloc_pgste = 1;
Carsten Otte402b0862008-03-25 18:47:10 +010041 } else {
Christian Borntraeger250cf772008-10-28 11:10:15 +010042 mm->context.has_pgste = 0;
43 mm->context.alloc_pgste = 0;
Carsten Otte402b0862008-03-25 18:47:10 +010044 }
Martin Schwidefsky6252d702008-02-09 18:24:37 +010045 mm->context.asce_limit = STACK_TOP_MAX;
46 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010047 return 0;
48}
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define destroy_context(mm) do { } while (0)
51
Gerald Schaeferc1821c22007-02-05 21:18:17 +010052#ifndef __s390x__
53#define LCTL_OPCODE "lctl"
Gerald Schaeferc1821c22007-02-05 21:18:17 +010054#else
55#define LCTL_OPCODE "lctlg"
Gerald Schaeferc1821c22007-02-05 21:18:17 +010056#endif
57
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020058static inline void update_mm(struct mm_struct *mm, struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010060 pgd_t *pgd = mm->pgd;
61
62 S390_lowcore.user_asce = mm->context.asce_bits | __pa(pgd);
Martin Schwidefskyb11b5332009-12-07 12:51:43 +010063 if (user_mode != HOME_SPACE_MODE) {
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020064 /* Load primary space page table origin. */
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020065 asm volatile(LCTL_OPCODE" 1,1,%0\n"
Martin Schwidefsky043d0702011-05-23 10:24:23 +020066 : : "m" (S390_lowcore.user_asce) );
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020067 } else
68 /* Load home space page table origin. */
69 asm volatile(LCTL_OPCODE" 13,13,%0"
70 : : "m" (S390_lowcore.user_asce) );
Martin Schwidefsky6252d702008-02-09 18:24:37 +010071 set_fs(current->thread.mm_segment);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
74static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
Gerald Schaeferc1821c22007-02-05 21:18:17 +010075 struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Rusty Russell005f8ee2009-03-26 15:25:01 +010077 cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020078 update_mm(next, tsk);
Martin Schwidefsky050eef32010-08-24 09:26:21 +020079 atomic_dec(&prev->context.attach_count);
80 WARN_ON(atomic_read(&prev->context.attach_count) < 0);
81 atomic_inc(&next->context.attach_count);
82 /* Check for TLBs not flushed yet */
83 if (next->context.flush_mm)
84 __tlb_flush_mm(next);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020087#define enter_lazy_tlb(mm,tsk) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define deactivate_mm(tsk,mm) do { } while (0)
89
Adrian Bunk4448aaf2005-11-08 21:34:42 -080090static inline void activate_mm(struct mm_struct *prev,
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 struct mm_struct *next)
92{
93 switch_mm(prev, next, current);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
Gerald Schaeferc1821c22007-02-05 21:18:17 +010096#endif /* __S390_MMU_CONTEXT_H */