blob: a6f0e7cc9cde2f341fba3fef347ea93240bb9372 [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>
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +020015#include <asm-generic/mm_hooks.h>
16
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010017static inline int init_new_context(struct task_struct *tsk,
18 struct mm_struct *mm)
19{
Martin Schwidefsky050eef32010-08-24 09:26:21 +020020 atomic_set(&mm->context.attach_count, 0);
21 mm->context.flush_mm = 0;
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010022 mm->context.asce_bits = _ASCE_TABLE_LENGTH | _ASCE_USER_BITS;
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010023#ifdef CONFIG_64BIT
Martin Schwidefsky6252d702008-02-09 18:24:37 +010024 mm->context.asce_bits |= _ASCE_TYPE_REGION3;
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010025#endif
Christian Borntraeger250cf772008-10-28 11:10:15 +010026 if (current->mm->context.alloc_pgste) {
27 /*
28 * alloc_pgste indicates, that any NEW context will be created
29 * with extended page tables. The old context is unchanged. The
30 * page table allocation and the page table operations will
31 * look at has_pgste to distinguish normal and extended page
32 * tables. The only way to create extended page tables is to
33 * set alloc_pgste and then create a new context (e.g. dup_mm).
34 * The page table allocation is called after init_new_context
35 * and if has_pgste is set, it will create extended page
36 * tables.
37 */
Carsten Otte402b0862008-03-25 18:47:10 +010038 mm->context.noexec = 0;
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 {
Martin Schwidefskyb11b5332009-12-07 12:51:43 +010042 mm->context.noexec = (user_mode == SECONDARY_SPACE_MODE);
Christian Borntraeger250cf772008-10-28 11:10:15 +010043 mm->context.has_pgste = 0;
44 mm->context.alloc_pgste = 0;
Carsten Otte402b0862008-03-25 18:47:10 +010045 }
Martin Schwidefsky6252d702008-02-09 18:24:37 +010046 mm->context.asce_limit = STACK_TOP_MAX;
47 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010048 return 0;
49}
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#define destroy_context(mm) do { } while (0)
52
Gerald Schaeferc1821c22007-02-05 21:18:17 +010053#ifndef __s390x__
54#define LCTL_OPCODE "lctl"
Gerald Schaeferc1821c22007-02-05 21:18:17 +010055#else
56#define LCTL_OPCODE "lctlg"
Gerald Schaeferc1821c22007-02-05 21:18:17 +010057#endif
58
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020059static inline void update_mm(struct mm_struct *mm, struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010061 pgd_t *pgd = mm->pgd;
62
63 S390_lowcore.user_asce = mm->context.asce_bits | __pa(pgd);
Martin Schwidefskyb11b5332009-12-07 12:51:43 +010064 if (user_mode != HOME_SPACE_MODE) {
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020065 /* Load primary space page table origin. */
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010066 pgd = mm->context.noexec ? get_shadow_table(pgd) : pgd;
67 S390_lowcore.user_exec_asce = mm->context.asce_bits | __pa(pgd);
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020068 asm volatile(LCTL_OPCODE" 1,1,%0\n"
69 : : "m" (S390_lowcore.user_exec_asce) );
70 } else
71 /* Load home space page table origin. */
72 asm volatile(LCTL_OPCODE" 13,13,%0"
73 : : "m" (S390_lowcore.user_asce) );
Martin Schwidefsky6252d702008-02-09 18:24:37 +010074 set_fs(current->thread.mm_segment);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76
77static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
Gerald Schaeferc1821c22007-02-05 21:18:17 +010078 struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
Rusty Russell005f8ee2009-03-26 15:25:01 +010080 cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020081 update_mm(next, tsk);
Martin Schwidefsky050eef32010-08-24 09:26:21 +020082 atomic_dec(&prev->context.attach_count);
83 WARN_ON(atomic_read(&prev->context.attach_count) < 0);
84 atomic_inc(&next->context.attach_count);
85 /* Check for TLBs not flushed yet */
86 if (next->context.flush_mm)
87 __tlb_flush_mm(next);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89
Martin Schwidefsky3610cce2007-10-22 12:52:47 +020090#define enter_lazy_tlb(mm,tsk) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define deactivate_mm(tsk,mm) do { } while (0)
92
Adrian Bunk4448aaf2005-11-08 21:34:42 -080093static inline void activate_mm(struct mm_struct *prev,
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 struct mm_struct *next)
95{
96 switch_mm(prev, next, current);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
Gerald Schaeferc1821c22007-02-05 21:18:17 +010099#endif /* __S390_MMU_CONTEXT_H */