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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * Switch a MMU context.
  3.  *
  4.  * This file is subject to the terms and conditions of the GNU General Public
  5.  * License.  See the file "COPYING" in the main directory of this archive
  6.  * for more details.
  7.  *
  8.  * Copyright (C) 1996, 1997, 1998, 1999 by Ralf Baechle
  9.  * Copyright (C) 1999 Silicon Graphics, Inc.
  10.  */
  11. #ifndef _ASM_MMU_CONTEXT_H
  12. #define _ASM_MMU_CONTEXT_H
  13. #include <linux/config.h>
  14. #include <linux/slab.h>
  15. #include <asm/pgalloc.h>
  16. #include <asm/pgtable.h>
  17. /*
  18.  * For the fast tlb miss handlers, we currently keep a per cpu array
  19.  * of pointers to the current pgd for each processor. Also, the proc.
  20.  * id is stuffed into the context register. This should be changed to
  21.  * use the processor id via current->processor, where current is stored
  22.  * in watchhi/lo. The context register should be used to contiguously
  23.  * map the page tables.
  24.  */
  25. #define TLBMISS_HANDLER_SETUP_PGD(pgd) 
  26. pgd_current[smp_processor_id()] = (unsigned long)(pgd)
  27. #define TLBMISS_HANDLER_SETUP() 
  28. set_context(((long)(&pgd_current[smp_processor_id()])) << 23); 
  29. TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir)
  30. extern unsigned long pgd_current[];
  31. #ifndef CONFIG_SMP
  32. #define CPU_CONTEXT(cpu, mm) (mm)->context
  33. #else
  34. #define CPU_CONTEXT(cpu, mm) (*((unsigned long *)((mm)->context) + cpu))
  35. #endif
  36. #define ASID_CACHE(cpu) cpu_data[cpu].asid_cache
  37. #define ASID_INC 0x1
  38. #define ASID_MASK 0xff
  39. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk, unsigned cpu)
  40. {
  41. }
  42. /*
  43.  *  All unused by hardware upper bits will be considered
  44.  *  as a software asid extension.
  45.  */
  46. #define ASID_VERSION_MASK  ((unsigned long)~(ASID_MASK|(ASID_MASK-1)))
  47. #define ASID_FIRST_VERSION ((unsigned long)(~ASID_VERSION_MASK) + 1)
  48. static inline void
  49. get_new_mmu_context(struct mm_struct *mm, unsigned long cpu)
  50. {
  51. unsigned long asid = ASID_CACHE(cpu);
  52. if (! ((asid += ASID_INC) & ASID_MASK) ) {
  53. flush_icache_all();
  54. local_flush_tlb_all(); /* start new asid cycle */
  55. if (!asid) /* fix version if needed */
  56. asid = ASID_FIRST_VERSION;
  57. }
  58. CPU_CONTEXT(cpu, mm) = ASID_CACHE(cpu) = asid;
  59. }
  60. /*
  61.  * Initialize the context related info for a new mm_struct
  62.  * instance.
  63.  */
  64. static inline int
  65. init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  66. {
  67. #ifndef CONFIG_SMP
  68. mm->context = 0;
  69. #else
  70. mm->context = (unsigned long)kmalloc(smp_num_cpus *
  71. sizeof(unsigned long), GFP_KERNEL);
  72. /*
  73.    * Init the "context" values so that a tlbpid allocation
  74.  * happens on the first switch.
  75.    */
  76. if (mm->context == 0)
  77. return -ENOMEM;
  78. memset((void *)mm->context, 0, smp_num_cpus * sizeof(unsigned long));
  79. #endif
  80. return 0;
  81. }
  82. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  83.                              struct task_struct *tsk, unsigned cpu)
  84. {
  85. /* Check if our ASID is of an older version and thus invalid */
  86. if ((CPU_CONTEXT(cpu, next) ^ ASID_CACHE(cpu)) & ASID_VERSION_MASK)
  87. get_new_mmu_context(next, cpu);
  88. set_entryhi(CPU_CONTEXT(cpu, next));
  89. TLBMISS_HANDLER_SETUP_PGD(next->pgd);
  90. }
  91. /*
  92.  * Destroy context related info for an mm_struct that is about
  93.  * to be put to rest.
  94.  */
  95. static inline void destroy_context(struct mm_struct *mm)
  96. {
  97. #ifdef CONFIG_SMP
  98. if (mm->context)
  99. kfree((void *)mm->context);
  100. #endif
  101. }
  102. /*
  103.  * After we have set current->mm to a new value, this activates
  104.  * the context for the new mm so we see the new mappings.
  105.  */
  106. static inline void
  107. activate_mm(struct mm_struct *prev, struct mm_struct *next)
  108. {
  109. /* Unconditionally get a new ASID.  */
  110. get_new_mmu_context(next, smp_processor_id());
  111. set_entryhi(CPU_CONTEXT(smp_processor_id(), next));
  112. TLBMISS_HANDLER_SETUP_PGD(next->pgd);
  113. }
  114. #endif /* _ASM_MMU_CONTEXT_H */