2 * include/asm-xtensa/mmu_context.h
4 * Switch an MMU context.
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
10 * Copyright (C) 2001 - 2005 Tensilica Inc.
13 #ifndef _XTENSA_MMU_CONTEXT_H
14 #define _XTENSA_MMU_CONTEXT_H
16 #include <linux/stringify.h>
18 #include <asm/pgtable.h>
19 #include <asm/cacheflush.h>
20 #include <asm/tlbflush.h>
21 #include <asm-generic/mm_hooks.h>
23 #define XCHAL_MMU_ASID_BITS 8
25 #if (XCHAL_HAVE_TLBS != 1)
26 # error "Linux must have an MMU!"
29 extern unsigned long asid_cache
;
32 * NO_CONTEXT is the invalid ASID value that we don't ever assign to
33 * any user or kernel context.
43 #define ASID_USER_FIRST 4
44 #define ASID_MASK ((1 << XCHAL_MMU_ASID_BITS) - 1)
45 #define ASID_INSERT(x) (0x03020001 | (((x) & ASID_MASK) << 8))
47 static inline void set_rasid_register (unsigned long val
)
49 __asm__
__volatile__ (" wsr %0, "__stringify(RASID
)"\n\t"
50 " isync\n" : : "a" (val
));
53 static inline unsigned long get_rasid_register (void)
56 __asm__
__volatile__ (" rsr %0,"__stringify(RASID
)"\n\t" : "=a" (tmp
));
61 __get_new_mmu_context(struct mm_struct
*mm
)
63 extern void flush_tlb_all(void);
64 if (! (++asid_cache
& ASID_MASK
) ) {
65 flush_tlb_all(); /* start new asid cycle */
66 asid_cache
+= ASID_USER_FIRST
;
68 mm
->context
= asid_cache
;
72 __load_mmu_context(struct mm_struct
*mm
)
74 set_rasid_register(ASID_INSERT(mm
->context
));
75 invalidate_page_directory();
79 * Initialize the context related info for a new mm_struct
84 init_new_context(struct task_struct
*tsk
, struct mm_struct
*mm
)
86 mm
->context
= NO_CONTEXT
;
91 * After we have set current->mm to a new value, this activates
92 * the context for the new mm so we see the new mappings.
95 activate_mm(struct mm_struct
*prev
, struct mm_struct
*next
)
97 /* Unconditionally get a new ASID. */
99 __get_new_mmu_context(next
);
100 __load_mmu_context(next
);
104 static inline void switch_mm(struct mm_struct
*prev
, struct mm_struct
*next
,
105 struct task_struct
*tsk
)
107 unsigned long asid
= asid_cache
;
109 /* Check if our ASID is of an older version and thus invalid */
111 if (next
->context
== NO_CONTEXT
|| ((next
->context
^asid
) & ~ASID_MASK
))
112 __get_new_mmu_context(next
);
114 __load_mmu_context(next
);
117 #define deactivate_mm(tsk, mm) do { } while(0)
120 * Destroy context related info for an mm_struct that is about
123 static inline void destroy_context(struct mm_struct
*mm
)
125 invalidate_page_directory();
129 static inline void enter_lazy_tlb(struct mm_struct
*mm
, struct task_struct
*tsk
)
135 #endif /* _XTENSA_MMU_CONTEXT_H */