0001
0002 #ifndef __ALPHA_MMU_CONTEXT_H
0003 #define __ALPHA_MMU_CONTEXT_H
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/mm_types.h>
0012 #include <linux/sched.h>
0013
0014 #include <asm/machvec.h>
0015 #include <asm/compiler.h>
0016 #include <asm-generic/mm_hooks.h>
0017
0018
0019
0020
0021
0022
0023
0024 #ifndef __EXTERN_INLINE
0025 #include <asm/io.h>
0026 #endif
0027
0028
0029 static inline unsigned long
0030 __reload_thread(struct pcb_struct *pcb)
0031 {
0032 register unsigned long a0 __asm__("$16");
0033 register unsigned long v0 __asm__("$0");
0034
0035 a0 = virt_to_phys(pcb);
0036 __asm__ __volatile__(
0037 "call_pal %2 #__reload_thread"
0038 : "=r"(v0), "=r"(a0)
0039 : "i"(PAL_swpctx), "r"(a0)
0040 : "$1", "$22", "$23", "$24", "$25");
0041
0042 return v0;
0043 }
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 #define EV4_MAX_ASN 63
0068 #define EV5_MAX_ASN 127
0069 #define EV6_MAX_ASN 255
0070
0071 #ifdef CONFIG_ALPHA_GENERIC
0072 # define MAX_ASN (alpha_mv.max_asn)
0073 #else
0074 # ifdef CONFIG_ALPHA_EV4
0075 # define MAX_ASN EV4_MAX_ASN
0076 # elif defined(CONFIG_ALPHA_EV5)
0077 # define MAX_ASN EV5_MAX_ASN
0078 # else
0079 # define MAX_ASN EV6_MAX_ASN
0080 # endif
0081 #endif
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 #include <asm/smp.h>
0092 #ifdef CONFIG_SMP
0093 #define cpu_last_asn(cpuid) (cpu_data[cpuid].last_asn)
0094 #else
0095 extern unsigned long last_asn;
0096 #define cpu_last_asn(cpuid) last_asn
0097 #endif
0098
0099 #define WIDTH_HARDWARE_ASN 8
0100 #define ASN_FIRST_VERSION (1UL << WIDTH_HARDWARE_ASN)
0101 #define HARDWARE_ASN_MASK ((1UL << WIDTH_HARDWARE_ASN) - 1)
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115 #ifndef __EXTERN_INLINE
0116 #define __EXTERN_INLINE extern inline
0117 #define __MMU_EXTERN_INLINE
0118 #endif
0119
0120 extern inline unsigned long
0121 __get_new_mm_context(struct mm_struct *mm, long cpu)
0122 {
0123 unsigned long asn = cpu_last_asn(cpu);
0124 unsigned long next = asn + 1;
0125
0126 if ((asn & HARDWARE_ASN_MASK) >= MAX_ASN) {
0127 tbiap();
0128 imb();
0129 next = (asn & ~HARDWARE_ASN_MASK) + ASN_FIRST_VERSION;
0130 }
0131 cpu_last_asn(cpu) = next;
0132 return next;
0133 }
0134
0135 __EXTERN_INLINE void
0136 ev5_switch_mm(struct mm_struct *prev_mm, struct mm_struct *next_mm,
0137 struct task_struct *next)
0138 {
0139
0140 unsigned long asn;
0141 unsigned long mmc;
0142 long cpu = smp_processor_id();
0143
0144 #ifdef CONFIG_SMP
0145 cpu_data[cpu].asn_lock = 1;
0146 barrier();
0147 #endif
0148 asn = cpu_last_asn(cpu);
0149 mmc = next_mm->context[cpu];
0150 if ((mmc ^ asn) & ~HARDWARE_ASN_MASK) {
0151 mmc = __get_new_mm_context(next_mm, cpu);
0152 next_mm->context[cpu] = mmc;
0153 }
0154 #ifdef CONFIG_SMP
0155 else
0156 cpu_data[cpu].need_new_asn = 1;
0157 #endif
0158
0159
0160
0161
0162 task_thread_info(next)->pcb.asn = mmc & HARDWARE_ASN_MASK;
0163 }
0164
0165 __EXTERN_INLINE void
0166 ev4_switch_mm(struct mm_struct *prev_mm, struct mm_struct *next_mm,
0167 struct task_struct *next)
0168 {
0169
0170
0171
0172
0173
0174
0175
0176
0177 if (prev_mm != next_mm)
0178 tbiap();
0179
0180
0181
0182 ev5_switch_mm(prev_mm, next_mm, next);
0183 }
0184
0185 extern void __load_new_mm_context(struct mm_struct *);
0186
0187 #ifdef CONFIG_SMP
0188 #define check_mmu_context() \
0189 do { \
0190 int cpu = smp_processor_id(); \
0191 cpu_data[cpu].asn_lock = 0; \
0192 barrier(); \
0193 if (cpu_data[cpu].need_new_asn) { \
0194 struct mm_struct * mm = current->active_mm; \
0195 cpu_data[cpu].need_new_asn = 0; \
0196 if (!mm->context[cpu]) \
0197 __load_new_mm_context(mm); \
0198 } \
0199 } while(0)
0200 #else
0201 #define check_mmu_context() do { } while(0)
0202 #endif
0203
0204 __EXTERN_INLINE void
0205 ev5_activate_mm(struct mm_struct *prev_mm, struct mm_struct *next_mm)
0206 {
0207 __load_new_mm_context(next_mm);
0208 }
0209
0210 __EXTERN_INLINE void
0211 ev4_activate_mm(struct mm_struct *prev_mm, struct mm_struct *next_mm)
0212 {
0213 __load_new_mm_context(next_mm);
0214 tbiap();
0215 }
0216
0217 #ifdef CONFIG_ALPHA_GENERIC
0218 # define switch_mm(a,b,c) alpha_mv.mv_switch_mm((a),(b),(c))
0219 # define activate_mm(x,y) alpha_mv.mv_activate_mm((x),(y))
0220 #else
0221 # ifdef CONFIG_ALPHA_EV4
0222 # define switch_mm(a,b,c) ev4_switch_mm((a),(b),(c))
0223 # define activate_mm(x,y) ev4_activate_mm((x),(y))
0224 # else
0225 # define switch_mm(a,b,c) ev5_switch_mm((a),(b),(c))
0226 # define activate_mm(x,y) ev5_activate_mm((x),(y))
0227 # endif
0228 #endif
0229
0230 #define init_new_context init_new_context
0231 static inline int
0232 init_new_context(struct task_struct *tsk, struct mm_struct *mm)
0233 {
0234 int i;
0235
0236 for_each_online_cpu(i)
0237 mm->context[i] = 0;
0238 if (tsk != current)
0239 task_thread_info(tsk)->pcb.ptbr
0240 = ((unsigned long)mm->pgd - IDENT_ADDR) >> PAGE_SHIFT;
0241 return 0;
0242 }
0243
0244 #define enter_lazy_tlb enter_lazy_tlb
0245 static inline void
0246 enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
0247 {
0248 task_thread_info(tsk)->pcb.ptbr
0249 = ((unsigned long)mm->pgd - IDENT_ADDR) >> PAGE_SHIFT;
0250 }
0251
0252 #include <asm-generic/mmu_context.h>
0253
0254 #ifdef __MMU_EXTERN_INLINE
0255 #undef __EXTERN_INLINE
0256 #undef __MMU_EXTERN_INLINE
0257 #endif
0258
0259 #endif