1e9564df7SGuo Ren /* SPDX-License-Identifier: GPL-2.0 */
2e9564df7SGuo Ren 
3e9564df7SGuo Ren #ifndef __ASM_CSKY_MMU_CONTEXT_H
4e9564df7SGuo Ren #define __ASM_CSKY_MMU_CONTEXT_H
5e9564df7SGuo Ren 
6e9564df7SGuo Ren #include <asm-generic/mm_hooks.h>
7e9564df7SGuo Ren #include <asm/setup.h>
8e9564df7SGuo Ren #include <asm/page.h>
9e9564df7SGuo Ren #include <asm/cacheflush.h>
10e9564df7SGuo Ren #include <asm/tlbflush.h>
11e9564df7SGuo Ren 
12e9564df7SGuo Ren #include <linux/errno.h>
13e9564df7SGuo Ren #include <linux/sched.h>
14e9564df7SGuo Ren #include <abi/ckmmu.h>
15e9564df7SGuo Ren 
1622d55f02SGuo Ren #define ASID_MASK		((1 << CONFIG_CPU_ASID_BITS) - 1)
1722d55f02SGuo Ren #define cpu_asid(mm)		(atomic64_read(&mm->context.asid) & ASID_MASK)
1822d55f02SGuo Ren 
1922d55f02SGuo Ren #define init_new_context(tsk,mm)	({ atomic64_set(&(mm)->context.asid, 0); 0; })
20e9564df7SGuo Ren 
2122d55f02SGuo Ren void check_and_switch_context(struct mm_struct *mm, unsigned int cpu);
2222d55f02SGuo Ren 
23e9564df7SGuo Ren static inline void
switch_mm(struct mm_struct * prev,struct mm_struct * next,struct task_struct * tsk)249d35dc30SGuo Ren switch_mm(struct mm_struct *prev, struct mm_struct *next,
25e9564df7SGuo Ren 	  struct task_struct *tsk)
26e9564df7SGuo Ren {
2722d55f02SGuo Ren 	unsigned int cpu = smp_processor_id();
2822d55f02SGuo Ren 
299d35dc30SGuo Ren 	if (prev != next)
3022d55f02SGuo Ren 		check_and_switch_context(next, cpu);
31e9564df7SGuo Ren 
32*3b756ccdSGuo Ren 	setup_pgd(next->pgd, next->context.asid.counter);
33997153b9SGuo Ren 
34997153b9SGuo Ren 	flush_icache_deferred(next);
35e9564df7SGuo Ren }
36746192ffSNicholas Piggin 
37746192ffSNicholas Piggin #include <asm-generic/mmu_context.h>
38746192ffSNicholas Piggin 
39e9564df7SGuo Ren #endif /* __ASM_CSKY_MMU_CONTEXT_H */
40