18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef __ASM_CSKY_MMU_CONTEXT_H
58c2ecf20Sopenharmony_ci#define __ASM_CSKY_MMU_CONTEXT_H
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <asm-generic/mm_hooks.h>
88c2ecf20Sopenharmony_ci#include <asm/setup.h>
98c2ecf20Sopenharmony_ci#include <asm/page.h>
108c2ecf20Sopenharmony_ci#include <asm/cacheflush.h>
118c2ecf20Sopenharmony_ci#include <asm/tlbflush.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/errno.h>
148c2ecf20Sopenharmony_ci#include <linux/sched.h>
158c2ecf20Sopenharmony_ci#include <abi/ckmmu.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define TLBMISS_HANDLER_SETUP_PGD(pgd) \
188c2ecf20Sopenharmony_ci	setup_pgd(__pa(pgd), false)
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define TLBMISS_HANDLER_SETUP_PGD_KERNEL(pgd) \
218c2ecf20Sopenharmony_ci	setup_pgd(__pa(pgd), true)
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define ASID_MASK		((1 << CONFIG_CPU_ASID_BITS) - 1)
248c2ecf20Sopenharmony_ci#define cpu_asid(mm)		(atomic64_read(&mm->context.asid) & ASID_MASK)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define init_new_context(tsk,mm)	({ atomic64_set(&(mm)->context.asid, 0); 0; })
278c2ecf20Sopenharmony_ci#define activate_mm(prev,next)		switch_mm(prev, next, current)
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#define destroy_context(mm)		do {} while (0)
308c2ecf20Sopenharmony_ci#define enter_lazy_tlb(mm, tsk)		do {} while (0)
318c2ecf20Sopenharmony_ci#define deactivate_mm(tsk, mm)		do {} while (0)
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_civoid check_and_switch_context(struct mm_struct *mm, unsigned int cpu);
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistatic inline void
368c2ecf20Sopenharmony_ciswitch_mm(struct mm_struct *prev, struct mm_struct *next,
378c2ecf20Sopenharmony_ci	  struct task_struct *tsk)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	unsigned int cpu = smp_processor_id();
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	if (prev != next)
428c2ecf20Sopenharmony_ci		check_and_switch_context(next, cpu);
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	TLBMISS_HANDLER_SETUP_PGD(next->pgd);
458c2ecf20Sopenharmony_ci	write_mmu_entryhi(next->context.asid.counter);
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	flush_icache_deferred(next);
488c2ecf20Sopenharmony_ci}
498c2ecf20Sopenharmony_ci#endif /* __ASM_CSKY_MMU_CONTEXT_H */
50