1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PARISC_MMU_CONTEXT_H
3 #define __PARISC_MMU_CONTEXT_H
6 #include <linux/sched.h>
7 #include <linux/atomic.h>
8 #include <linux/spinlock.h>
9 #include <asm-generic/mm_hooks.h>
11 /* on PA-RISC, we actually have enough contexts to justify an allocator
14 extern unsigned long alloc_sid(void);
15 extern void free_sid(unsigned long);
17 #define init_new_context init_new_context
19 init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21 BUG_ON(atomic_read(&mm->mm_users) != 1);
23 mm->context.space_id = alloc_sid();
27 #define destroy_context destroy_context
29 destroy_context(struct mm_struct *mm)
31 free_sid(mm->context.space_id);
32 mm->context.space_id = 0;
35 static inline unsigned long __space_to_prot(mm_context_t context)
37 #if SPACEID_SHIFT == 0
38 return context.space_id << 1;
40 return context.space_id >> (SPACEID_SHIFT - 1);
44 static inline void load_context(mm_context_t context)
46 mtsp(context.space_id, SR_USER);
47 mtctl(__space_to_prot(context), 8);
50 static inline void switch_mm_irqs_off(struct mm_struct *prev,
51 struct mm_struct *next, struct task_struct *tsk)
54 #ifdef CONFIG_TLB_PTLOCK
55 /* put physical address of page_table_lock in cr28 (tr4)
57 spinlock_t *pgd_lock = &next->page_table_lock;
58 mtctl(__pa(__ldcw_align(&pgd_lock->rlock.raw_lock)), 28);
60 mtctl(__pa(next->pgd), 25);
61 load_context(next->context);
65 static inline void switch_mm(struct mm_struct *prev,
66 struct mm_struct *next, struct task_struct *tsk)
73 local_irq_save(flags);
74 switch_mm_irqs_off(prev, next, tsk);
75 local_irq_restore(flags);
77 #define switch_mm_irqs_off switch_mm_irqs_off
79 #define activate_mm activate_mm
80 static inline void activate_mm(struct mm_struct *prev, struct mm_struct *next)
83 * Activate_mm is our one chance to allocate a space id
84 * for a new mm created in the exec path. There's also
85 * some lazy tlb stuff, which is currently dead code, but
86 * we only allocate a space id if one hasn't been allocated
87 * already, so we should be OK.
90 BUG_ON(next == &init_mm); /* Should never happen */
92 if (next->context.space_id == 0)
93 next->context.space_id = alloc_sid();
95 switch_mm(prev,next,current);
98 #include <asm-generic/mmu_context.h>