1 /* $Id: mmu_context.h,v 1.3 1998/10/16 19:22:54 ralf Exp $
3 * Switch a MMU context.
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
9 * Copyright (C) 1996, 1997, 1998 by Ralf Baechle
11 #ifndef __ASM_MIPS_MMU_CONTEXT_H
12 #define __ASM_MIPS_MMU_CONTEXT_H
14 /* Fuck. The f-word is here so you can grep for it :-) */
15 extern unsigned long asid_cache
;
17 /* I patch, therefore I am ... */
18 #define ASID_INC(asid) \
19 ({ unsigned long __asid = asid; \
20 __asm__("1:\taddiu\t%0,0\t\t\t\t# patched\n\t" \
21 ".section\t__asid_inc,\"a\"\n\t" \
27 #define ASID_MASK(asid) \
28 ({ unsigned long __asid = asid; \
29 __asm__("1:\tandi\t%0,%1,0\t\t\t# patched\n\t" \
30 ".section\t__asid_mask,\"a\"\n\t" \
36 #define ASID_VERSION_MASK \
37 ({ unsigned long __asid; \
38 __asm__("1:\tli\t%0,0\t\t\t\t# patched\n\t" \
39 ".section\t__asid_version_mask,\"a\"\n\t" \
44 #define ASID_FIRST_VERSION \
45 ({ unsigned long __asid = asid; \
46 __asm__("1:\tli\t%0,0\t\t\t\t# patched\n\t" \
47 ".section\t__asid_first_version,\"a\"\n\t" \
53 #define ASID_FIRST_VERSION_R3000 0x1000
54 #define ASID_FIRST_VERSION_R4000 0x100
57 get_new_mmu_context(struct mm_struct
*mm
, unsigned long asid
)
59 if (!ASID_MASK((asid
= ASID_INC(asid
)))) {
60 flush_tlb_all(); /* start new asid cycle */
61 if (!asid
) /* fix version if needed */
62 asid
= ASID_FIRST_VERSION
;
64 mm
->context
= asid_cache
= asid
;
68 get_mmu_context(struct task_struct
*p
)
70 struct mm_struct
*mm
= p
->mm
;
73 unsigned long asid
= asid_cache
;
74 /* Check if our ASID is of an older version and thus invalid */
75 if ((mm
->context
^ asid
) & ASID_VERSION_MASK
)
76 get_new_mmu_context(mm
, asid
);
81 * Initialize the context related info for a new mm_struct
84 extern inline void init_new_context(struct mm_struct
*mm
)
90 * Destroy context related info for an mm_struct that is about
93 extern inline void destroy_context(struct mm_struct
*mm
)
99 * After we have set current->mm to a new value, this activates
100 * the context for the new mm so we see the new mappings.
102 extern inline void activate_context(struct task_struct
*tsk
)
104 get_mmu_context(tsk
);
105 set_entryhi(tsk
->mm
->context
);
108 extern void __asid_setup(unsigned int inc
, unsigned int mask
,
109 unsigned int version_mask
, unsigned int first_version
);
111 extern inline void r3000_asid_setup(void)
113 __asid_setup(0x40, 0xfc0, 0xf000, ASID_FIRST_VERSION_R3000
);
116 extern inline void r6000_asid_setup(void)
118 panic("r6000_asid_setup: implement me"); /* No idea ... */
121 extern inline void tfp_asid_setup(void)
123 panic("tfp_asid_setup: implement me"); /* No idea ... */
126 extern inline void r4xx0_asid_setup(void)
128 __asid_setup(1, 0xff, 0xff00, ASID_FIRST_VERSION_R4000
);
131 /* R10000 has the same ASID mechanism as the R4000. */
132 #define andes_asid_setup r4xx0_asid_setup
134 #endif /* __ASM_MIPS_MMU_CONTEXT_H */