1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_SCORE_MMU_CONTEXT_H
3 #define _ASM_SCORE_MMU_CONTEXT_H
5 #include <linux/errno.h>
6 #include <linux/sched.h>
7 #include <linux/mm_types.h>
8 #include <linux/slab.h>
10 #include <asm-generic/mm_hooks.h>
12 #include <asm/cacheflush.h>
13 #include <asm/tlbflush.h>
14 #include <asm/scoreregs.h>
17 * For the fast tlb miss handlers, we keep a per cpu array of pointers
18 * to the current pgd for each processor. Also, the proc. id is stuffed
19 * into the context register.
21 extern unsigned long asid_cache
;
22 extern unsigned long pgd_current
;
24 #define TLBMISS_HANDLER_SETUP_PGD(pgd) (pgd_current = (unsigned long)(pgd))
26 #define TLBMISS_HANDLER_SETUP() \
28 write_c0_context(0); \
29 TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir) \
33 * All unused by hardware upper bits will be considered
34 * as a software asid extension.
36 #define ASID_VERSION_MASK 0xfffff000
37 #define ASID_FIRST_VERSION 0x1000
39 /* PEVN --------- VPN ---------- --ASID--- -NA- */
40 /* binary: 0000 0000 0000 0000 0000 0000 0001 0000 */
41 /* binary: 0000 0000 0000 0000 0000 1111 1111 0000 */
43 #define ASID_MASK 0xff0
45 static inline void enter_lazy_tlb(struct mm_struct
*mm
,
46 struct task_struct
*tsk
)
50 get_new_mmu_context(struct mm_struct
*mm
)
52 unsigned long asid
= asid_cache
+ ASID_INC
;
54 if (!(asid
& ASID_MASK
)) {
55 local_flush_tlb_all(); /* start new asid cycle */
56 if (!asid
) /* fix version if needed */
57 asid
= ASID_FIRST_VERSION
;
65 * Initialize the context related info for a new mm_struct
69 init_new_context(struct task_struct
*tsk
, struct mm_struct
*mm
)
75 static inline void switch_mm(struct mm_struct
*prev
, struct mm_struct
*next
,
76 struct task_struct
*tsk
)
80 local_irq_save(flags
);
81 if ((next
->context
^ asid_cache
) & ASID_VERSION_MASK
)
82 get_new_mmu_context(next
);
84 pevn_set(next
->context
);
85 TLBMISS_HANDLER_SETUP_PGD(next
->pgd
);
86 local_irq_restore(flags
);
90 * Destroy context related info for an mm_struct that is about
93 static inline void destroy_context(struct mm_struct
*mm
)
97 deactivate_mm(struct task_struct
*task
, struct mm_struct
*mm
)
101 * After we have set current->mm to a new value, this activates
102 * the context for the new mm so we see the new mappings.
105 activate_mm(struct mm_struct
*prev
, struct mm_struct
*next
)
109 local_irq_save(flags
);
110 get_new_mmu_context(next
);
111 pevn_set(next
->context
);
112 TLBMISS_HANDLER_SETUP_PGD(next
->pgd
);
113 local_irq_restore(flags
);
116 #endif /* _ASM_SCORE_MMU_CONTEXT_H */