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 
58263a67eSPaul Mundt #ifdef CONFIG_CPU_HAS_PTEAEX
set_asid(unsigned long asid)68263a67eSPaul Mundt static inline void set_asid(unsigned long asid)
78263a67eSPaul Mundt {
88263a67eSPaul Mundt 	__raw_writel(asid, MMU_PTEAEX);
98263a67eSPaul Mundt }
108263a67eSPaul Mundt 
get_asid(void)118263a67eSPaul Mundt static inline unsigned long get_asid(void)
128263a67eSPaul Mundt {
138263a67eSPaul Mundt 	return __raw_readl(MMU_PTEAEX) & MMU_CONTEXT_ASID_MASK;
148263a67eSPaul Mundt }
158263a67eSPaul Mundt #else
set_asid(unsigned long asid)16f15cbe6fSPaul Mundt static inline void set_asid(unsigned long asid)
17f15cbe6fSPaul Mundt {
18f15cbe6fSPaul Mundt 	unsigned long __dummy;
19f15cbe6fSPaul Mundt 
20f15cbe6fSPaul Mundt 	__asm__ __volatile__ ("mov.l	%2, %0\n\t"
21f15cbe6fSPaul Mundt 			      "and	%3, %0\n\t"
22f15cbe6fSPaul Mundt 			      "or	%1, %0\n\t"
23f15cbe6fSPaul Mundt 			      "mov.l	%0, %2"
24f15cbe6fSPaul Mundt 			      : "=&r" (__dummy)
25f15cbe6fSPaul Mundt 			      : "r" (asid), "m" (__m(MMU_PTEH)),
26f15cbe6fSPaul Mundt 			        "r" (0xffffff00));
27f15cbe6fSPaul Mundt }
28f15cbe6fSPaul Mundt 
get_asid(void)29f15cbe6fSPaul Mundt static inline unsigned long get_asid(void)
30f15cbe6fSPaul Mundt {
31f15cbe6fSPaul Mundt 	unsigned long asid;
32f15cbe6fSPaul Mundt 
33f15cbe6fSPaul Mundt 	__asm__ __volatile__ ("mov.l	%1, %0"
34f15cbe6fSPaul Mundt 			      : "=r" (asid)
35f15cbe6fSPaul Mundt 			      : "m" (__m(MMU_PTEH)));
36f15cbe6fSPaul Mundt 	asid &= MMU_CONTEXT_ASID_MASK;
37f15cbe6fSPaul Mundt 	return asid;
38f15cbe6fSPaul Mundt }
398263a67eSPaul Mundt #endif /* CONFIG_CPU_HAS_PTEAEX */
40f15cbe6fSPaul Mundt 
41f15cbe6fSPaul Mundt /* MMU_TTB is used for optimizing the fault handling. */
set_TTB(pgd_t * pgd)42f15cbe6fSPaul Mundt static inline void set_TTB(pgd_t *pgd)
43f15cbe6fSPaul Mundt {
449d56dd3bSPaul Mundt 	__raw_writel((unsigned long)pgd, MMU_TTB);
45f15cbe6fSPaul Mundt }
46f15cbe6fSPaul Mundt 
get_TTB(void)47f15cbe6fSPaul Mundt static inline pgd_t *get_TTB(void)
48f15cbe6fSPaul Mundt {
499d56dd3bSPaul Mundt 	return (pgd_t *)__raw_readl(MMU_TTB);
50f15cbe6fSPaul Mundt }
51f15cbe6fSPaul Mundt #endif /* __ASM_SH_MMU_CONTEXT_32_H */
52