1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2f15cbe6fSPaul Mundt #ifndef __ASM_SH_MMU_CONTEXT_32_H
3f15cbe6fSPaul Mundt #define __ASM_SH_MMU_CONTEXT_32_H
4f15cbe6fSPaul Mundt 
5f15cbe6fSPaul Mundt /*
6f15cbe6fSPaul Mundt  * Destroy context related info for an mm_struct that is about
7f15cbe6fSPaul Mundt  * to be put to rest.
8f15cbe6fSPaul Mundt  */
9f15cbe6fSPaul Mundt static inline void destroy_context(struct mm_struct *mm)
10f15cbe6fSPaul Mundt {
11f15cbe6fSPaul Mundt 	/* Do nothing */
12f15cbe6fSPaul Mundt }
13f15cbe6fSPaul Mundt 
148263a67eSPaul Mundt #ifdef CONFIG_CPU_HAS_PTEAEX
158263a67eSPaul Mundt static inline void set_asid(unsigned long asid)
168263a67eSPaul Mundt {
178263a67eSPaul Mundt 	__raw_writel(asid, MMU_PTEAEX);
188263a67eSPaul Mundt }
198263a67eSPaul Mundt 
208263a67eSPaul Mundt static inline unsigned long get_asid(void)
218263a67eSPaul Mundt {
228263a67eSPaul Mundt 	return __raw_readl(MMU_PTEAEX) & MMU_CONTEXT_ASID_MASK;
238263a67eSPaul Mundt }
248263a67eSPaul Mundt #else
25f15cbe6fSPaul Mundt static inline void set_asid(unsigned long asid)
26f15cbe6fSPaul Mundt {
27f15cbe6fSPaul Mundt 	unsigned long __dummy;
28f15cbe6fSPaul Mundt 
29f15cbe6fSPaul Mundt 	__asm__ __volatile__ ("mov.l	%2, %0\n\t"
30f15cbe6fSPaul Mundt 			      "and	%3, %0\n\t"
31f15cbe6fSPaul Mundt 			      "or	%1, %0\n\t"
32f15cbe6fSPaul Mundt 			      "mov.l	%0, %2"
33f15cbe6fSPaul Mundt 			      : "=&r" (__dummy)
34f15cbe6fSPaul Mundt 			      : "r" (asid), "m" (__m(MMU_PTEH)),
35f15cbe6fSPaul Mundt 			        "r" (0xffffff00));
36f15cbe6fSPaul Mundt }
37f15cbe6fSPaul Mundt 
38f15cbe6fSPaul Mundt static inline unsigned long get_asid(void)
39f15cbe6fSPaul Mundt {
40f15cbe6fSPaul Mundt 	unsigned long asid;
41f15cbe6fSPaul Mundt 
42f15cbe6fSPaul Mundt 	__asm__ __volatile__ ("mov.l	%1, %0"
43f15cbe6fSPaul Mundt 			      : "=r" (asid)
44f15cbe6fSPaul Mundt 			      : "m" (__m(MMU_PTEH)));
45f15cbe6fSPaul Mundt 	asid &= MMU_CONTEXT_ASID_MASK;
46f15cbe6fSPaul Mundt 	return asid;
47f15cbe6fSPaul Mundt }
488263a67eSPaul Mundt #endif /* CONFIG_CPU_HAS_PTEAEX */
49f15cbe6fSPaul Mundt 
50f15cbe6fSPaul Mundt /* MMU_TTB is used for optimizing the fault handling. */
51f15cbe6fSPaul Mundt static inline void set_TTB(pgd_t *pgd)
52f15cbe6fSPaul Mundt {
539d56dd3bSPaul Mundt 	__raw_writel((unsigned long)pgd, MMU_TTB);
54f15cbe6fSPaul Mundt }
55f15cbe6fSPaul Mundt 
56f15cbe6fSPaul Mundt static inline pgd_t *get_TTB(void)
57f15cbe6fSPaul Mundt {
589d56dd3bSPaul Mundt 	return (pgd_t *)__raw_readl(MMU_TTB);
59f15cbe6fSPaul Mundt }
60f15cbe6fSPaul Mundt #endif /* __ASM_SH_MMU_CONTEXT_32_H */
61