2 * Copyright (C) 2004-2006 Atmel Corporation
4 * ASID handling taken from SH implementation.
5 * Copyright (C) 1999 Niibe Yutaka
6 * Copyright (C) 2003 Paul Mundt
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 #ifndef __ASM_AVR32_MMU_CONTEXT_H
13 #define __ASM_AVR32_MMU_CONTEXT_H
15 #include <asm/tlbflush.h>
16 #include <asm/pgalloc.h>
17 #include <asm/sysreg.h>
18 #include <asm-generic/mm_hooks.h>
21 * The MMU "context" consists of two things:
22 * (a) TLB cache version
23 * (b) ASID (Address Space IDentifier)
25 #define MMU_CONTEXT_ASID_MASK 0x000000ff
26 #define MMU_CONTEXT_VERSION_MASK 0xffffff00
27 #define MMU_CONTEXT_FIRST_VERSION 0x00000100
30 #define MMU_NO_ASID 0x100
32 /* Virtual Page Number mask */
33 #define MMU_VPN_MASK 0xfffff000
35 /* Cache of MMU context last used */
36 extern unsigned long mmu_context_cache
;
39 * Get MMU context if needed
42 get_mmu_context(struct mm_struct
*mm
)
44 unsigned long mc
= mmu_context_cache
;
46 if (((mm
->context
^ mc
) & MMU_CONTEXT_VERSION_MASK
) == 0)
47 /* It's up to date, do nothing */
50 /* It's old, we need to get new context with new version */
51 mc
= ++mmu_context_cache
;
52 if (!(mc
& MMU_CONTEXT_ASID_MASK
)) {
54 * We have exhausted all ASIDs of this version.
55 * Flush the TLB and start new cycle.
59 * Fix version. Note that we avoid version #0
60 * to distinguish NO_CONTEXT.
63 mmu_context_cache
= mc
= MMU_CONTEXT_FIRST_VERSION
;
69 * Initialize the context related info for a new mm_struct
72 static inline int init_new_context(struct task_struct
*tsk
,
75 mm
->context
= NO_CONTEXT
;
80 * Destroy context related info for an mm_struct that is about
83 static inline void destroy_context(struct mm_struct
*mm
)
88 static inline void set_asid(unsigned long asid
)
90 /* XXX: We're destroying TLBEHI[8:31] */
91 sysreg_write(TLBEHI
, asid
& MMU_CONTEXT_ASID_MASK
);
95 static inline unsigned long get_asid(void)
99 asid
= sysreg_read(TLBEHI
);
100 return asid
& MMU_CONTEXT_ASID_MASK
;
103 static inline void activate_context(struct mm_struct
*mm
)
106 set_asid(mm
->context
& MMU_CONTEXT_ASID_MASK
);
109 static inline void switch_mm(struct mm_struct
*prev
,
110 struct mm_struct
*next
,
111 struct task_struct
*tsk
)
113 if (likely(prev
!= next
)) {
114 unsigned long __pgdir
= (unsigned long)next
->pgd
;
116 sysreg_write(PTBR
, __pgdir
);
117 activate_context(next
);
121 #define deactivate_mm(tsk,mm) do { } while(0)
123 #define activate_mm(prev, next) switch_mm((prev), (next), NULL)
126 enter_lazy_tlb(struct mm_struct
*mm
, struct task_struct
*tsk
)
131 static inline void enable_mmu(void)
133 sysreg_write(MMUCR
, (SYSREG_BIT(MMUCR_S
)
135 | SYSREG_BIT(MMUCR_I
)));
136 nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
138 if (mmu_context_cache
== NO_CONTEXT
)
139 mmu_context_cache
= MMU_CONTEXT_FIRST_VERSION
;
141 set_asid(mmu_context_cache
& MMU_CONTEXT_ASID_MASK
);
144 static inline void disable_mmu(void)
146 sysreg_write(MMUCR
, SYSREG_BIT(MMUCR_S
));
149 #endif /* __ASM_AVR32_MMU_CONTEXT_H */