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((unsigned long) smp_processor_id() << (23 + 3)); 
  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. #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
  38. #define ASID_INC 0x40
  39. #define ASID_MASK 0xfc0
  40. #else /* FIXME: not correct for R6000, R8000 */
  41. #define ASID_INC 0x1
  42. #define ASID_MASK 0xff
  43. #endif
  44. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk, unsigned cpu)
  45. {
  46. }
  47. /*
  48.  *  All unused by hardware upper bits will be considered
  49.  *  as a software asid extension.
  50.  */
  51. #define ASID_VERSION_MASK  ((unsigned long)~(ASID_MASK|(ASID_MASK-1)))
  52. #define ASID_FIRST_VERSION ((unsigned long)(~ASID_VERSION_MASK) + 1)
  53. static inline void
  54. get_new_mmu_context(struct mm_struct *mm, unsigned long cpu)
  55. {
  56. unsigned long asid = ASID_CACHE(cpu);
  57. if (! ((asid += ASID_INC) & ASID_MASK) ) {
  58. flush_icache_all();
  59. local_flush_tlb_all(); /* start new asid cycle */
  60. if (!asid) /* fix version if needed */
  61. asid = ASID_FIRST_VERSION;
  62. }
  63. CPU_CONTEXT(cpu, mm) = ASID_CACHE(cpu) = asid;
  64. }
  65. /*
  66.  * Initialize the context related info for a new mm_struct
  67.  * instance.
  68.  */
  69. static inline int
  70. init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  71. {
  72. #ifndef CONFIG_SMP
  73. mm->context = 0;
  74. #else
  75. mm->context = (unsigned long)kmalloc(smp_num_cpus *
  76. sizeof(unsigned long), GFP_KERNEL);
  77. /*
  78.    * Init the "context" values so that a tlbpid allocation
  79.  * happens on the first switch.
  80.    */
  81. if (mm->context == 0)
  82. return -ENOMEM;
  83. memset((void *)mm->context, 0, smp_num_cpus * sizeof(unsigned long));
  84. #endif
  85. return 0;
  86. }
  87. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  88.                              struct task_struct *tsk, unsigned cpu)
  89. {
  90. /* Check if our ASID is of an older version and thus invalid */
  91. if ((CPU_CONTEXT(cpu, next) ^ ASID_CACHE(cpu)) & ASID_VERSION_MASK)
  92. get_new_mmu_context(next, cpu);
  93. set_entryhi(CPU_CONTEXT(cpu, next));
  94. TLBMISS_HANDLER_SETUP_PGD(next->pgd);
  95. }
  96. /*
  97.  * Destroy context related info for an mm_struct that is about
  98.  * to be put to rest.
  99.  */
  100. static inline void destroy_context(struct mm_struct *mm)
  101. {
  102. #ifdef CONFIG_SMP
  103. if (mm->context)
  104. kfree((void *)mm->context);
  105. #endif
  106. }
  107. /*
  108.  * After we have set current->mm to a new value, this activates
  109.  * the context for the new mm so we see the new mappings.
  110.  */
  111. static inline void
  112. activate_mm(struct mm_struct *prev, struct mm_struct *next)
  113. {
  114. /* Unconditionally get a new ASID.  */
  115. get_new_mmu_context(next, smp_processor_id());
  116. set_entryhi(CPU_CONTEXT(smp_processor_id(), next));
  117. TLBMISS_HANDLER_SETUP_PGD(next->pgd);
  118. }
  119. #endif /* _ASM_MMU_CONTEXT_H */