1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_M32R_MMU_CONTEXT_H
3 #define _ASM_M32R_MMU_CONTEXT_H
8 #define MMU_CONTEXT_ASID_MASK (0x000000FF)
9 #define MMU_CONTEXT_VERSION_MASK (0xFFFFFF00)
10 #define MMU_CONTEXT_FIRST_VERSION (0x00000100)
11 #define NO_CONTEXT (0x00000000)
15 #include <linux/atomic.h>
16 #include <linux/mm_types.h>
18 #include <asm/pgalloc.h>
20 #include <asm/tlbflush.h>
21 #include <asm-generic/mm_hooks.h>
24 * Cache of MMU context last used.
27 extern unsigned long mmu_context_cache_dat
;
28 #define mmu_context_cache mmu_context_cache_dat
29 #define mm_context(mm) mm->context
30 #else /* not CONFIG_SMP */
31 extern unsigned long mmu_context_cache_dat
[];
32 #define mmu_context_cache mmu_context_cache_dat[smp_processor_id()]
33 #define mm_context(mm) mm->context[smp_processor_id()]
34 #endif /* not CONFIG_SMP */
36 #define set_tlb_tag(entry, tag) (*entry = (tag & PAGE_MASK)|get_asid())
37 #define set_tlb_data(entry, data) (*entry = (data | _PAGE_PRESENT))
40 #define enter_lazy_tlb(mm, tsk) do { } while (0)
42 static inline void get_new_mmu_context(struct mm_struct
*mm
)
44 unsigned long mc
= ++mmu_context_cache
;
46 if (!(mc
& MMU_CONTEXT_ASID_MASK
)) {
47 /* We exhaust ASID of this version.
48 Flush all TLB and start new cycle. */
49 local_flush_tlb_all();
50 /* Fix version if needed.
51 Note that we avoid version #0 to distinguish NO_CONTEXT. */
53 mmu_context_cache
= mc
= MMU_CONTEXT_FIRST_VERSION
;
59 * Get MMU context if needed.
61 static inline void get_mmu_context(struct mm_struct
*mm
)
64 unsigned long mc
= mmu_context_cache
;
66 /* Check if we have old version of context.
67 If it's old, we need to get new context with new version. */
68 if ((mm_context(mm
) ^ mc
) & MMU_CONTEXT_VERSION_MASK
)
69 get_new_mmu_context(mm
);
74 * Initialize the context related info for a new mm_struct
77 static inline int init_new_context(struct task_struct
*tsk
,
81 mm
->context
= NO_CONTEXT
;
82 #else /* CONFIG_SMP */
83 int num_cpus
= num_online_cpus();
86 for (i
= 0 ; i
< num_cpus
; i
++)
87 mm
->context
[i
] = NO_CONTEXT
;
88 #endif /* CONFIG_SMP */
94 * Destroy context related info for an mm_struct that is about
97 #define destroy_context(mm) do { } while (0)
99 static inline void set_asid(unsigned long asid
)
101 *(volatile unsigned long *)MASID
= (asid
& MMU_CONTEXT_ASID_MASK
);
104 static inline unsigned long get_asid(void)
108 asid
= *(volatile long *)MASID
;
109 asid
&= MMU_CONTEXT_ASID_MASK
;
115 * After we have set current->mm to a new value, this activates
116 * the context for the new mm so we see the new mappings.
118 static inline void activate_context(struct mm_struct
*mm
)
121 set_asid(mm_context(mm
) & MMU_CONTEXT_ASID_MASK
);
124 static inline void switch_mm(struct mm_struct
*prev
,
125 struct mm_struct
*next
, struct task_struct
*tsk
)
128 int cpu
= smp_processor_id();
129 #endif /* CONFIG_SMP */
133 cpumask_set_cpu(cpu
, mm_cpumask(next
));
134 #endif /* CONFIG_SMP */
135 /* Set MPTB = next->pgd */
136 *(volatile unsigned long *)MPTB
= (unsigned long)next
->pgd
;
137 activate_context(next
);
141 if (!cpumask_test_and_set_cpu(cpu
, mm_cpumask(next
)))
142 activate_context(next
);
143 #endif /* CONFIG_SMP */
146 #define deactivate_mm(tsk, mm) do { } while (0)
148 #define activate_mm(prev, next) \
149 switch_mm((prev), (next), NULL)
151 #else /* not CONFIG_MMU */
152 #define get_mmu_context(mm) do { } while (0)
153 #define init_new_context(tsk,mm) (0)
154 #define destroy_context(mm) do { } while (0)
155 #define set_asid(asid) do { } while (0)
156 #define get_asid() (0)
157 #define activate_context(mm) do { } while (0)
158 #define switch_mm(prev,next,tsk) do { } while (0)
159 #define deactivate_mm(mm,tsk) do { } while (0)
160 #define activate_mm(prev,next) do { } while (0)
161 #define enter_lazy_tlb(mm,tsk) do { } while (0)
162 #endif /* not CONFIG_MMU */
164 #endif /* not __ASSEMBLY__ */
166 #endif /* __KERNEL__ */
167 #endif /* _ASM_M32R_MMU_CONTEXT_H */