blob: 59be257644335f7fff70b54ca65661633b9eaa22 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __PARISC_MMU_CONTEXT_H
2#define __PARISC_MMU_CONTEXT_H
3
4#include <linux/mm.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +04005#include <linux/sched.h>
Arun Sharma600634972011-07-26 16:09:06 -07006#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <asm/pgalloc.h>
8#include <asm/pgtable.h>
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +02009#include <asm-generic/mm_hooks.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
12{
13}
14
15/* on PA-RISC, we actually have enough contexts to justify an allocator
16 * for them. prumpf */
17
18extern unsigned long alloc_sid(void);
19extern void free_sid(unsigned long);
20
21static inline int
22init_new_context(struct task_struct *tsk, struct mm_struct *mm)
23{
24 BUG_ON(atomic_read(&mm->mm_users) != 1);
25
26 mm->context = alloc_sid();
27 return 0;
28}
29
30static inline void
31destroy_context(struct mm_struct *mm)
32{
33 free_sid(mm->context);
34 mm->context = 0;
35}
36
Kyle McMartin70da2d92008-12-22 23:58:31 +000037static inline unsigned long __space_to_prot(mm_context_t context)
Kyle McMartina60715f2008-12-22 12:29:02 -050038{
39#if SPACEID_SHIFT == 0
40 return context << 1;
41#else
42 return context >> (SPACEID_SHIFT - 1);
43#endif
44}
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046static inline void load_context(mm_context_t context)
47{
48 mtsp(context, 3);
Kyle McMartina60715f2008-12-22 12:29:02 -050049 mtctl(__space_to_prot(context), 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51
52static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, struct task_struct *tsk)
53{
54
55 if (prev != next) {
56 mtctl(__pa(next->pgd), 25);
57 load_context(next->context);
58 }
59}
60
61#define deactivate_mm(tsk,mm) do { } while (0)
62
63static inline void activate_mm(struct mm_struct *prev, struct mm_struct *next)
64{
65 /*
66 * Activate_mm is our one chance to allocate a space id
67 * for a new mm created in the exec path. There's also
68 * some lazy tlb stuff, which is currently dead code, but
69 * we only allocate a space id if one hasn't been allocated
70 * already, so we should be OK.
71 */
72
73 BUG_ON(next == &init_mm); /* Should never happen */
74
75 if (next->context == 0)
76 next->context = alloc_sid();
77
78 switch_mm(prev,next,current);
79}
80#endif