mmu_context.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. #ifndef __X86_64_MMU_CONTEXT_H
  2. #define __X86_64_MMU_CONTEXT_H
  3. #include <linux/config.h>
  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 <linux/spinlock.h>
  10. /*
  11.  * possibly do the LDT unload here?
  12.  */
  13. #define destroy_context(mm)     do { } while(0)
  14. #define init_new_context(tsk,mm)    ({ rwlock_init(&(mm)->context.ldtlock); 0; })
  15. #ifdef CONFIG_SMP
  16. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk, unsigned cpu)
  17. {
  18. if(cpu_tlbstate[cpu].state == TLBSTATE_OK)
  19. cpu_tlbstate[cpu].state = TLBSTATE_LAZY;
  20. }
  21. #else
  22. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk, unsigned cpu)
  23. {
  24. }
  25. #endif
  26. #define activate_mm(prev, next) 
  27. switch_mm((prev),(next),NULL,smp_processor_id())
  28. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, 
  29.      struct task_struct *tsk, unsigned cpu)
  30. {
  31. if (prev != next) {
  32. /* stop flush ipis for the previous mm */
  33. clear_bit(cpu, &prev->cpu_vm_mask);
  34. /*
  35.  * Re-load LDT if necessary
  36.  */
  37. if (prev->context.segments != next->context.segments)
  38. load_LDT(next);
  39. #ifdef CONFIG_SMP
  40. cpu_tlbstate[cpu].state = TLBSTATE_OK;
  41. cpu_tlbstate[cpu].active_mm = next;
  42. #endif
  43. set_bit(cpu, &next->cpu_vm_mask);
  44. set_bit(cpu, &next->context.cpuvalid);
  45. /* Re-load page tables */
  46. *read_pda(level4_pgt) = __pa(next->pgd) | _PAGE_TABLE;
  47. __flush_tlb();
  48. }
  49. #ifdef CONFIG_SMP
  50. else {
  51. cpu_tlbstate[cpu].state = TLBSTATE_OK;
  52. if(cpu_tlbstate[cpu].active_mm != next)
  53. out_of_line_bug();
  54. if(!test_and_set_bit(cpu, &next->cpu_vm_mask)) {
  55. /* We were in lazy tlb mode and leave_mm disabled 
  56.  * tlb flush IPI delivery. We must flush our tlb.
  57.  */
  58. local_flush_tlb();
  59. }
  60. if (!test_and_set_bit(cpu, &next->context.cpuvalid))
  61. load_LDT(next);
  62. }
  63. #endif
  64. }
  65. #endif