1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __PARISC_MMU_CONTEXT_H 3 #define __PARISC_MMU_CONTEXT_H 4 5 #include <linux/mm.h> 6 #include <linux/sched.h> 7 #include <linux/atomic.h> 8 #include <asm-generic/mm_hooks.h> 9 10 /* on PA-RISC, we actually have enough contexts to justify an allocator 11 * for them. prumpf */ 12 13 extern unsigned long alloc_sid(void); 14 extern void free_sid(unsigned long); 15 16 #define init_new_context init_new_context 17 static inline int 18 init_new_context(struct task_struct *tsk, struct mm_struct *mm) 19 { 20 BUG_ON(atomic_read(&mm->mm_users) != 1); 21 22 mm->context = alloc_sid(); 23 return 0; 24 } 25 26 #define destroy_context destroy_context 27 static inline void 28 destroy_context(struct mm_struct *mm) 29 { 30 free_sid(mm->context); 31 mm->context = 0; 32 } 33 34 static inline unsigned long __space_to_prot(mm_context_t context) 35 { 36 #if SPACEID_SHIFT == 0 37 return context << 1; 38 #else 39 return context >> (SPACEID_SHIFT - 1); 40 #endif 41 } 42 43 static inline void load_context(mm_context_t context) 44 { 45 mtsp(context, 3); 46 mtctl(__space_to_prot(context), 8); 47 } 48 49 static inline void switch_mm_irqs_off(struct mm_struct *prev, 50 struct mm_struct *next, struct task_struct *tsk) 51 { 52 if (prev != next) { 53 mtctl(__pa(next->pgd), 25); 54 load_context(next->context); 55 } 56 } 57 58 static inline void switch_mm(struct mm_struct *prev, 59 struct mm_struct *next, struct task_struct *tsk) 60 { 61 unsigned long flags; 62 63 if (prev == next) 64 return; 65 66 local_irq_save(flags); 67 switch_mm_irqs_off(prev, next, tsk); 68 local_irq_restore(flags); 69 } 70 #define switch_mm_irqs_off switch_mm_irqs_off 71 72 #define activate_mm activate_mm 73 static inline void activate_mm(struct mm_struct *prev, struct mm_struct *next) 74 { 75 /* 76 * Activate_mm is our one chance to allocate a space id 77 * for a new mm created in the exec path. There's also 78 * some lazy tlb stuff, which is currently dead code, but 79 * we only allocate a space id if one hasn't been allocated 80 * already, so we should be OK. 81 */ 82 83 BUG_ON(next == &init_mm); /* Should never happen */ 84 85 if (next->context == 0) 86 next->context = alloc_sid(); 87 88 switch_mm(prev,next,current); 89 } 90 91 #include <asm-generic/mmu_context.h> 92 93 #endif 94