7e2aa23fccbf5f762f51be38e051273fde05897d
[sfrench/cifs-2.6.git] / include / asm-x86 / mmu_context_64.h
1 #ifndef __X86_64_MMU_CONTEXT_H
2 #define __X86_64_MMU_CONTEXT_H
3
4 #include <asm/desc.h>
5 #include <asm/atomic.h>
6 #include <asm/pgalloc.h>
7 #include <asm/pda.h>
8 #include <asm/pgtable.h>
9 #include <asm/tlbflush.h>
10 #include <asm-generic/mm_hooks.h>
11
12 /*
13  * possibly do the LDT unload here?
14  */
15 int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
16 void destroy_context(struct mm_struct *mm);
17
18 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
19 {
20 #ifdef CONFIG_SMP
21         if (read_pda(mmu_state) == TLBSTATE_OK) 
22                 write_pda(mmu_state, TLBSTATE_LAZY);
23 #endif
24 }
25
26 static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, 
27                              struct task_struct *tsk)
28 {
29         unsigned cpu = smp_processor_id();
30         if (likely(prev != next)) {
31                 /* stop flush ipis for the previous mm */
32                 cpu_clear(cpu, prev->cpu_vm_mask);
33 #ifdef CONFIG_SMP
34                 write_pda(mmu_state, TLBSTATE_OK);
35                 write_pda(active_mm, next);
36 #endif
37                 cpu_set(cpu, next->cpu_vm_mask);
38                 load_cr3(next->pgd);
39
40                 if (unlikely(next->context.ldt != prev->context.ldt)) 
41                         load_LDT_nolock(&next->context);
42         }
43 #ifdef CONFIG_SMP
44         else {
45                 write_pda(mmu_state, TLBSTATE_OK);
46                 if (read_pda(active_mm) != next)
47                         BUG();
48                 if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) {
49                         /* We were in lazy tlb mode and leave_mm disabled 
50                          * tlb flush IPI delivery. We must reload CR3
51                          * to make sure to use no freed page tables.
52                          */
53                         load_cr3(next->pgd);
54                         load_LDT_nolock(&next->context);
55                 }
56         }
57 #endif
58 }
59
60 #define deactivate_mm(tsk,mm)   do { \
61         load_gs_index(0); \
62         asm volatile("movl %0,%%fs"::"r"(0));  \
63 } while(0)
64
65 #define activate_mm(prev, next) \
66         switch_mm((prev),(next),NULL)
67
68
69 #endif