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
10 #include <asm/cpu/mmu_context.h>
11 #include <asm/tlbflush.h>
12 #include <asm/pgalloc.h>
13 #include <asm/uaccess.h>
17 * The MMU "context" consists of two things:
18 * (a) TLB cache version (or round, cycle whatever expression you like)
19 * (b) ASID (Address Space IDentifier)
23 * Cache of MMU context last used.
25 extern unsigned long mmu_context_cache
;
27 #define MMU_CONTEXT_ASID_MASK 0x000000ff
28 #define MMU_CONTEXT_VERSION_MASK 0xffffff00
29 #define MMU_CONTEXT_FIRST_VERSION 0x00000100
32 /* ASID is 8-bit value, so it can't be 0x100 */
33 #define MMU_NO_ASID 0x100
36 * Virtual Page Number mask
38 #define MMU_VPN_MASK 0xfffff000
42 * Get MMU context if needed.
44 static __inline__
void
45 get_mmu_context(struct mm_struct
*mm
)
47 extern void flush_tlb_all(void);
48 unsigned long mc
= mmu_context_cache
;
50 /* Check if we have old version of context. */
51 if (((mm
->context
^ mc
) & MMU_CONTEXT_VERSION_MASK
) == 0)
52 /* It's up to date, do nothing */
55 /* It's old, we need to get new context with new version. */
56 mc
= ++mmu_context_cache
;
57 if (!(mc
& MMU_CONTEXT_ASID_MASK
)) {
59 * We exhaust ASID of this version.
60 * Flush all TLB and start new cycle.
64 * Fix version; Note that we avoid version #0
65 * to distingush NO_CONTEXT.
68 mmu_context_cache
= mc
= MMU_CONTEXT_FIRST_VERSION
;
74 * Initialize the context related info for a new mm_struct
77 static __inline__
int init_new_context(struct task_struct
*tsk
,
80 mm
->context
= NO_CONTEXT
;
86 * Destroy context related info for an mm_struct that is about
89 static __inline__
void destroy_context(struct mm_struct
*mm
)
94 static __inline__
void set_asid(unsigned long asid
)
96 unsigned long __dummy
;
98 __asm__
__volatile__ ("mov.l %2, %0\n\t"
103 : "r" (asid
), "m" (__m(MMU_PTEH
)),
107 static __inline__
unsigned long get_asid(void)
111 __asm__
__volatile__ ("mov.l %1, %0"
113 : "m" (__m(MMU_PTEH
)));
114 asid
&= MMU_CONTEXT_ASID_MASK
;
119 * After we have set current->mm to a new value, this activates
120 * the context for the new mm so we see the new mappings.
122 static __inline__
void activate_context(struct mm_struct
*mm
)
125 set_asid(mm
->context
& MMU_CONTEXT_ASID_MASK
);
128 /* MMU_TTB can be used for optimizing the fault handling.
129 (Currently not used) */
130 static __inline__
void switch_mm(struct mm_struct
*prev
,
131 struct mm_struct
*next
,
132 struct task_struct
*tsk
)
134 if (likely(prev
!= next
)) {
135 unsigned long __pgdir
= (unsigned long)next
->pgd
;
137 __asm__
__volatile__("mov.l %0, %1"
139 : "r" (__pgdir
), "m" (__m(MMU_TTB
)));
140 activate_context(next
);
144 #define deactivate_mm(tsk,mm) do { } while (0)
146 #define activate_mm(prev, next) \
147 switch_mm((prev),(next),NULL)
149 static __inline__
void
150 enter_lazy_tlb(struct mm_struct
*mm
, struct task_struct
*tsk
)
153 #else /* !CONFIG_MMU */
154 #define get_mmu_context(mm) do { } while (0)
155 #define init_new_context(tsk,mm) (0)
156 #define destroy_context(mm) do { } while (0)
157 #define set_asid(asid) do { } while (0)
158 #define get_asid() (0)
159 #define activate_context(mm) do { } while (0)
160 #define switch_mm(prev,next,tsk) do { } while (0)
161 #define deactivate_mm(tsk,mm) do { } while (0)
162 #define activate_mm(prev,next) do { } while (0)
163 #define enter_lazy_tlb(mm,tsk) do { } while (0)
164 #endif /* CONFIG_MMU */
166 #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4)
168 * If this processor has an MMU, we need methods to turn it off/on ..
169 * paging_init() will also have to be updated for the processor in
172 static inline void enable_mmu(void)
175 ctrl_outl(MMU_CONTROL_INIT
, MMUCR
);
177 /* The manual suggests doing some nops after turning on the MMU */
178 __asm__
__volatile__ ("nop;nop;nop;nop;nop;nop;nop;nop\n\t");
180 if (mmu_context_cache
== NO_CONTEXT
)
181 mmu_context_cache
= MMU_CONTEXT_FIRST_VERSION
;
183 set_asid(mmu_context_cache
& MMU_CONTEXT_ASID_MASK
);
186 static inline void disable_mmu(void)
190 cr
= ctrl_inl(MMUCR
);
191 cr
&= ~MMU_CONTROL_INIT
;
192 ctrl_outl(cr
, MMUCR
);
193 __asm__
__volatile__ ("nop;nop;nop;nop;nop;nop;nop;nop\n\t");
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 /* __ASM_SH_MMU_CONTEXT_H */