1 #ifndef _ASM_M32R_MMU_CONTEXT_H
2 #define _ASM_M32R_MMU_CONTEXT_H
6 #include <linux/config.h>
10 #define MMU_CONTEXT_ASID_MASK (0x000000FF)
11 #define MMU_CONTEXT_VERSION_MASK (0xFFFFFF00)
12 #define MMU_CONTEXT_FIRST_VERSION (0x00000100)
13 #define NO_CONTEXT (0x00000000)
18 #include <linux/config.h>
19 #include <asm/atomic.h>
20 #include <asm/pgalloc.h>
22 #include <asm/tlbflush.h>
25 * Cache of MMU context last used.
28 extern unsigned long mmu_context_cache_dat
;
29 #define mmu_context_cache mmu_context_cache_dat
30 #define mm_context(mm) mm->context
31 #else /* not CONFIG_SMP */
32 extern unsigned long mmu_context_cache_dat
[];
33 #define mmu_context_cache mmu_context_cache_dat[smp_processor_id()]
34 #define mm_context(mm) mm->context[smp_processor_id()]
35 #endif /* not CONFIG_SMP */
37 #define set_tlb_tag(entry, tag) (*entry = (tag & PAGE_MASK)|get_asid())
38 #define set_tlb_data(entry, data) (*entry = (data | _PAGE_PRESENT))
41 #define enter_lazy_tlb(mm, tsk) do { } while (0)
43 static inline void get_new_mmu_context(struct mm_struct
*mm
)
45 unsigned long mc
= ++mmu_context_cache
;
47 if (!(mc
& MMU_CONTEXT_ASID_MASK
)) {
48 /* We exhaust ASID of this version.
49 Flush all TLB and start new cycle. */
50 local_flush_tlb_all();
51 /* Fix version if needed.
52 Note that we avoid version #0 to distingush NO_CONTEXT. */
54 mmu_context_cache
= mc
= MMU_CONTEXT_FIRST_VERSION
;
60 * Get MMU context if needed.
62 static inline void get_mmu_context(struct mm_struct
*mm
)
65 unsigned long mc
= mmu_context_cache
;
67 /* Check if we have old version of context.
68 If it's old, we need to get new context with new version. */
69 if ((mm_context(mm
) ^ mc
) & MMU_CONTEXT_VERSION_MASK
)
70 get_new_mmu_context(mm
);
75 * Initialize the context related info for a new mm_struct
78 static inline int init_new_context(struct task_struct
*tsk
,
82 mm
->context
= NO_CONTEXT
;
83 #else /* CONFIG_SMP */
84 int num_cpus
= num_online_cpus();
87 for (i
= 0 ; i
< num_cpus
; i
++)
88 mm
->context
[i
] = NO_CONTEXT
;
89 #endif /* CONFIG_SMP */
95 * Destroy context related info for an mm_struct that is about
98 #define destroy_context(mm) do { } while (0)
100 static inline void set_asid(unsigned long asid
)
102 *(volatile unsigned long *)MASID
= (asid
& MMU_CONTEXT_ASID_MASK
);
105 static inline unsigned long get_asid(void)
109 asid
= *(volatile long *)MASID
;
110 asid
&= MMU_CONTEXT_ASID_MASK
;
116 * After we have set current->mm to a new value, this activates
117 * the context for the new mm so we see the new mappings.
119 static inline void activate_context(struct mm_struct
*mm
)
122 set_asid(mm_context(mm
) & MMU_CONTEXT_ASID_MASK
);
125 static inline void switch_mm(struct mm_struct
*prev
,
126 struct mm_struct
*next
, struct task_struct
*tsk
)
129 int cpu
= smp_processor_id();
130 #endif /* CONFIG_SMP */
134 cpu_set(cpu
, next
->cpu_vm_mask
);
135 #endif /* CONFIG_SMP */
136 /* Set MPTB = next->pgd */
137 *(volatile unsigned long *)MPTB
= (unsigned long)next
->pgd
;
138 activate_context(next
);
142 if (!cpu_test_and_set(cpu
, next
->cpu_vm_mask
))
143 activate_context(next
);
144 #endif /* CONFIG_SMP */
147 #define deactivate_mm(tsk, mm) do { } while (0)
149 #define activate_mm(prev, next) \
150 switch_mm((prev), (next), NULL)
153 #define get_mmu_context(mm) do { } while (0)
154 #define init_new_context(tsk,mm) (0)
155 #define destroy_context(mm) do { } while (0)
156 #define set_asid(asid) do { } while (0)
157 #define get_asid() (0)
158 #define activate_context(mm) do { } while (0)
159 #define switch_mm(prev,next,tsk) do { } while (0)
160 #define deactivate_mm(mm,tsk) do { } while (0)
161 #define activate_mm(prev,next) do { } while (0)
162 #define enter_lazy_tlb(mm,tsk) do { } while (0)
163 #endif /* CONFIG_MMU */
166 #endif /* not __ASSEMBLY__ */
168 #endif /* __KERNEL__ */
170 #endif /* _ASM_M32R_MMU_CONTEXT_H */