blob: 73382eba02dccf2d8373bc860e4ebbe7fe7cac0a [file] [log] [blame]
Paul Mackerras047ea782005-11-19 20:17:32 +11001#ifndef __ASM_POWERPC_MMU_CONTEXT_H
2#define __ASM_POWERPC_MMU_CONTEXT_H
Arnd Bergmann88ced032005-12-16 22:43:46 +01003#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
Benjamin Herrenschmidt5e696612008-12-18 19:13:24 +00005#include <linux/kernel.h>
6#include <linux/mm.h>
7#include <linux/sched.h>
8#include <linux/spinlock.h>
Kumar Gala80a7cc62007-07-03 03:22:05 -05009#include <asm/mmu.h>
10#include <asm/cputable.h>
11#include <asm-generic/mm_hooks.h>
Benjamin Herrenschmidt5e696612008-12-18 19:13:24 +000012#include <asm/cputhreads.h>
Kumar Gala80a7cc62007-07-03 03:22:05 -050013
14/*
Benjamin Herrenschmidt5e696612008-12-18 19:13:24 +000015 * Most if the context management is out of line
Kumar Gala80a7cc62007-07-03 03:22:05 -050016 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070017extern int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
18extern void destroy_context(struct mm_struct *mm);
19
Benjamin Herrenschmidt5e696612008-12-18 19:13:24 +000020extern void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021extern void switch_slb(struct task_struct *tsk, struct mm_struct *mm);
Benjamin Herrenschmidt5e696612008-12-18 19:13:24 +000022extern void set_context(unsigned long id, pgd_t *pgd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Benjamin Herrenschmidt6f0ef0f2009-07-23 23:15:26 +000024#ifdef CONFIG_PPC_BOOK3S_64
Alexander Grafe85a4712009-11-02 12:02:30 +000025extern int __init_new_context(void);
26extern void __destroy_context(int context_id);
Benjamin Herrenschmidt6f0ef0f2009-07-23 23:15:26 +000027static inline void mmu_context_init(void) { }
28#else
Alexander Grafc83ec262010-04-16 00:11:36 +020029extern unsigned long __init_new_context(void);
30extern void __destroy_context(unsigned long context_id);
Benjamin Herrenschmidt6f0ef0f2009-07-23 23:15:26 +000031extern void mmu_context_init(void);
32#endif
33
Tseng-Hui (Frank) Lin851d2e22011-05-02 20:43:04 +000034extern void switch_cop(struct mm_struct *next);
35extern int use_cop(unsigned long acop, struct mm_struct *mm);
36extern void drop_cop(unsigned long acop, struct mm_struct *mm);
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/*
39 * switch_mm is the entry point called from the architecture independent
Viresh Kumar0a0fca92013-06-04 13:10:24 +053040 * code in kernel/sched/core.c
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 */
42static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
43 struct task_struct *tsk)
44{
Benjamin Herrenschmidt5e696612008-12-18 19:13:24 +000045 /* Mark this context has been used on the new CPU */
Rusty Russell56aa4122009-03-15 18:16:43 +000046 cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Benjamin Herrenschmidt5e696612008-12-18 19:13:24 +000048 /* 32-bit keeps track of the current PGDIR in the thread struct */
49#ifdef CONFIG_PPC32
50 tsk->thread.pgdir = next->pgd;
51#endif /* CONFIG_PPC32 */
52
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +000053 /* 64-bit Book3E keeps track of current PGD in the PACA */
54#ifdef CONFIG_PPC_BOOK3E_64
55 get_paca()->pgd = next->pgd;
56#endif
Benjamin Herrenschmidt5e696612008-12-18 19:13:24 +000057 /* Nothing else to do if we aren't actually switching */
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 if (prev == next)
59 return;
60
Tseng-Hui (Frank) Lin851d2e22011-05-02 20:43:04 +000061#ifdef CONFIG_PPC_ICSWX
62 /* Switch coprocessor context only if prev or next uses a coprocessor */
63 if (prev->context.acop || next->context.acop)
64 switch_cop(next);
65#endif /* CONFIG_PPC_ICSWX */
66
Benjamin Herrenschmidt5e696612008-12-18 19:13:24 +000067 /* We must stop all altivec streams before changing the HW
68 * context
69 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#ifdef CONFIG_ALTIVEC
71 if (cpu_has_feature(CPU_FTR_ALTIVEC))
72 asm volatile ("dssall");
73#endif /* CONFIG_ALTIVEC */
74
Benjamin Herrenschmidt5e696612008-12-18 19:13:24 +000075 /* The actual HW switching method differs between the various
76 * sub architectures.
77 */
78#ifdef CONFIG_PPC_STD_MMU_64
Michael Ellerman13b3d132014-07-10 12:29:20 +100079 switch_slb(tsk, next);
Benjamin Herrenschmidt5e696612008-12-18 19:13:24 +000080#else
81 /* Out of line for now */
82 switch_mmu_context(prev, next);
83#endif
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
87#define deactivate_mm(tsk,mm) do { } while (0)
88
89/*
90 * After we have set current->mm to a new value, this activates
91 * the context for the new mm so we see the new mappings.
92 */
93static inline void activate_mm(struct mm_struct *prev, struct mm_struct *next)
94{
95 unsigned long flags;
96
97 local_irq_save(flags);
98 switch_mm(prev, next, current);
99 local_irq_restore(flags);
100}
101
Benjamin Herrenschmidt5e696612008-12-18 19:13:24 +0000102/* We don't currently use enter_lazy_tlb() for anything */
103static inline void enter_lazy_tlb(struct mm_struct *mm,
104 struct task_struct *tsk)
105{
Benjamin Herrenschmidt25d21ad2009-07-23 23:15:47 +0000106 /* 64-bit Book3E keeps track of current PGD in the PACA */
107#ifdef CONFIG_PPC_BOOK3E_64
108 get_paca()->pgd = NULL;
109#endif
Benjamin Herrenschmidt5e696612008-12-18 19:13:24 +0000110}
111
Arnd Bergmann88ced032005-12-16 22:43:46 +0100112#endif /* __KERNEL__ */
Paul Mackerras047ea782005-11-19 20:17:32 +1100113#endif /* __ASM_POWERPC_MMU_CONTEXT_H */