2 * Copyright (C) 1999 Niibe Yutaka
3 * Copyright (C) 2003 Paul Mundt
5 * ASID handling idea taken from MIPS implementation.
7 #ifndef __ASM_SH_MMU_CONTEXT_H
8 #define __ASM_SH_MMU_CONTEXT_H
11 #include <asm/cpu/mmu_context.h>
12 #include <asm/tlbflush.h>
13 #include <asm/pgalloc.h>
14 #include <asm/uaccess.h>
18 * The MMU "context" consists of two things:
19 * (a) TLB cache version (or round, cycle whatever expression you like)
20 * (b) ASID (Address Space IDentifier)
24 * Cache of MMU context last used.
26 extern unsigned long mmu_context_cache
;
28 #define MMU_CONTEXT_ASID_MASK 0x000000ff
29 #define MMU_CONTEXT_VERSION_MASK 0xffffff00
30 #define MMU_CONTEXT_FIRST_VERSION 0x00000100
33 /* ASID is 8-bit value, so it can't be 0x100 */
34 #define MMU_NO_ASID 0x100
37 * Virtual Page Number mask
39 #define MMU_VPN_MASK 0xfffff000
43 * Get MMU context if needed.
45 static __inline__
void
46 get_mmu_context(struct mm_struct
*mm
)
48 extern void flush_tlb_all(void);
49 unsigned long mc
= mmu_context_cache
;
51 /* Check if we have old version of context. */
52 if (((mm
->context
.id
^ mc
) & MMU_CONTEXT_VERSION_MASK
) == 0)
53 /* It's up to date, do nothing */
56 /* It's old, we need to get new context with new version. */
57 mc
= ++mmu_context_cache
;
58 if (!(mc
& MMU_CONTEXT_ASID_MASK
)) {
60 * We exhaust ASID of this version.
61 * Flush all TLB and start new cycle.
65 * Fix version; Note that we avoid version #0
66 * to distingush NO_CONTEXT.
69 mmu_context_cache
= mc
= MMU_CONTEXT_FIRST_VERSION
;
75 * Initialize the context related info for a new mm_struct
78 static __inline__
int init_new_context(struct task_struct
*tsk
,
81 mm
->context
.id
= NO_CONTEXT
;
87 * Destroy context related info for an mm_struct that is about
90 static __inline__
void destroy_context(struct mm_struct
*mm
)
95 static __inline__
void set_asid(unsigned long asid
)
97 unsigned long __dummy
;
99 __asm__
__volatile__ ("mov.l %2, %0\n\t"
104 : "r" (asid
), "m" (__m(MMU_PTEH
)),
108 static __inline__
unsigned long get_asid(void)
112 __asm__
__volatile__ ("mov.l %1, %0"
114 : "m" (__m(MMU_PTEH
)));
115 asid
&= MMU_CONTEXT_ASID_MASK
;
120 * After we have set current->mm to a new value, this activates
121 * the context for the new mm so we see the new mappings.
123 static __inline__
void activate_context(struct mm_struct
*mm
)
126 set_asid(mm
->context
.id
& MMU_CONTEXT_ASID_MASK
);
129 /* MMU_TTB can be used for optimizing the fault handling.
130 (Currently not used) */
131 static __inline__
void switch_mm(struct mm_struct
*prev
,
132 struct mm_struct
*next
,
133 struct task_struct
*tsk
)
135 if (likely(prev
!= next
)) {
136 unsigned long __pgdir
= (unsigned long)next
->pgd
;
138 __asm__
__volatile__("mov.l %0, %1"
140 : "r" (__pgdir
), "m" (__m(MMU_TTB
)));
141 activate_context(next
);
145 #define deactivate_mm(tsk,mm) do { } while (0)
147 #define activate_mm(prev, next) \
148 switch_mm((prev),(next),NULL)
150 static __inline__
void
151 enter_lazy_tlb(struct mm_struct
*mm
, struct task_struct
*tsk
)
154 #else /* !CONFIG_MMU */
155 #define get_mmu_context(mm) do { } while (0)
156 #define init_new_context(tsk,mm) (0)
157 #define destroy_context(mm) do { } while (0)
158 #define set_asid(asid) do { } while (0)
159 #define get_asid() (0)
160 #define activate_context(mm) do { } while (0)
161 #define switch_mm(prev,next,tsk) do { } while (0)
162 #define deactivate_mm(tsk,mm) do { } while (0)
163 #define activate_mm(prev,next) do { } while (0)
164 #define enter_lazy_tlb(mm,tsk) do { } while (0)
165 #endif /* CONFIG_MMU */
167 #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4)
169 * If this processor has an MMU, we need methods to turn it off/on ..
170 * paging_init() will also have to be updated for the processor in
173 static inline void enable_mmu(void)
176 ctrl_outl(MMU_CONTROL_INIT
, MMUCR
);
179 if (mmu_context_cache
== NO_CONTEXT
)
180 mmu_context_cache
= MMU_CONTEXT_FIRST_VERSION
;
182 set_asid(mmu_context_cache
& MMU_CONTEXT_ASID_MASK
);
185 static inline void disable_mmu(void)
189 cr
= ctrl_inl(MMUCR
);
190 cr
&= ~MMU_CONTROL_INIT
;
191 ctrl_outl(cr
, MMUCR
);
197 * MMU control handlers for processors lacking memory
198 * management hardware.
200 #define enable_mmu() do { BUG(); } while (0)
201 #define disable_mmu() do { BUG(); } while (0)
204 #endif /* __KERNEL__ */
205 #endif /* __ASM_SH_MMU_CONTEXT_H */