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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* $Id: mmu_context.h,v 1.51 2001/08/17 04:55:09 kanoj Exp $ */
  2. #ifndef __SPARC64_MMU_CONTEXT_H
  3. #define __SPARC64_MMU_CONTEXT_H
  4. /* Derived heavily from Linus's Alpha/AXP ASN code... */
  5. #include <asm/page.h>
  6. /*
  7.  * For the 8k pagesize kernel, use only 10 hw context bits to optimize some shifts in
  8.  * the fast tlbmiss handlers, instead of all 13 bits (specifically for vpte offset
  9.  * calculation). For other pagesizes, this optimization in the tlbhandlers can not be 
  10.  * done; but still, all 13 bits can not be used because the tlb handlers use "andcc"
  11.  * instruction which sign extends 13 bit arguments.
  12.  */
  13. #if PAGE_SHIFT == 13
  14. #define CTX_VERSION_SHIFT 10
  15. #define TAG_CONTEXT_BITS 0x3ff
  16. #else
  17. #define CTX_VERSION_SHIFT 12
  18. #define TAG_CONTEXT_BITS 0xfff
  19. #endif
  20. #ifndef __ASSEMBLY__
  21. #include <linux/spinlock.h>
  22. #include <asm/system.h>
  23. #include <asm/spitfire.h>
  24. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk, unsigned cpu)
  25. {
  26. }
  27. extern spinlock_t ctx_alloc_lock;
  28. extern unsigned long tlb_context_cache;
  29. extern unsigned long mmu_context_bmap[];
  30. #define CTX_VERSION_MASK ((~0UL) << CTX_VERSION_SHIFT)
  31. #define CTX_FIRST_VERSION ((1UL << CTX_VERSION_SHIFT) + 1UL)
  32. #define CTX_VALID(__ctx)
  33.  (!(((__ctx) ^ tlb_context_cache) & CTX_VERSION_MASK))
  34. #define CTX_HWBITS(__ctx) ((__ctx) & ~CTX_VERSION_MASK)
  35. extern void get_new_mmu_context(struct mm_struct *mm);
  36. /* Initialize a new mmu context.  This is invoked when a new
  37.  * address space instance (unique or shared) is instantiated.
  38.  * This just needs to set mm->context to an invalid context.
  39.  */
  40. #define init_new_context(__tsk, __mm) (((__mm)->context = 0UL), 0)
  41. /* Destroy a dead context.  This occurs when mmput drops the
  42.  * mm_users count to zero, the mmaps have been released, and
  43.  * all the page tables have been flushed.  Our job is to destroy
  44.  * any remaining processor-specific state, and in the sparc64
  45.  * case this just means freeing up the mmu context ID held by
  46.  * this task if valid.
  47.  */
  48. #define destroy_context(__mm)
  49. do { spin_lock(&ctx_alloc_lock);
  50. if (CTX_VALID((__mm)->context)) {
  51. unsigned long nr = CTX_HWBITS((__mm)->context);
  52. mmu_context_bmap[nr>>6] &= ~(1UL << (nr & 63));
  53. }
  54. spin_unlock(&ctx_alloc_lock);
  55. } while(0)
  56. /* Reload the two core values used by TLB miss handler
  57.  * processing on sparc64.  They are:
  58.  * 1) The physical address of mm->pgd, when full page
  59.  *    table walks are necessary, this is where the
  60.  *    search begins.
  61.  * 2) A "PGD cache".  For 32-bit tasks only pgd[0] is
  62.  *    ever used since that maps the entire low 4GB
  63.  *    completely.  To speed up TLB miss processing we
  64.  *    make this value available to the handlers.  This
  65.  *    decreases the amount of memory traffic incurred.
  66.  */
  67. #define reload_tlbmiss_state(__tsk, __mm) 
  68. do { 
  69. register unsigned long paddr asm("o5"); 
  70. register unsigned long pgd_cache asm("o4"); 
  71. paddr = __pa((__mm)->pgd); 
  72. pgd_cache = 0UL; 
  73. if ((__tsk)->thread.flags & SPARC_FLAG_32BIT) 
  74. pgd_cache = pgd_val((__mm)->pgd[0]) << 11UL; 
  75. __asm__ __volatile__("wrpr %%g0, 0x494, %%pstatent" 
  76.      "mov %3, %%g4nt" 
  77.      "mov %0, %%g7nt" 
  78.      "stxa %1, [%%g4] %2nt" 
  79.      "membar #Syncnt" 
  80.      "wrpr %%g0, 0x096, %%pstate" 
  81.      : /* no outputs */ 
  82.      : "r" (paddr), "r" (pgd_cache),
  83.        "i" (ASI_DMMU), "i" (TSB_REG)); 
  84. } while(0)
  85. /* Set MMU context in the actual hardware. */
  86. #define load_secondary_context(__mm) 
  87. __asm__ __volatile__("stxa %0, [%1] %2nt" 
  88.      "flush %%g6" 
  89.      : /* No outputs */ 
  90.      : "r" (CTX_HWBITS((__mm)->context)), 
  91.        "r" (0x10), "i" (ASI_DMMU))
  92. extern void __flush_tlb_mm(unsigned long, unsigned long);
  93. /* Switch the current MM context. */
  94. static inline void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk, int cpu)
  95. {
  96. unsigned long ctx_valid;
  97. spin_lock(&mm->page_table_lock);
  98. if (CTX_VALID(mm->context))
  99. ctx_valid = 1;
  100.         else
  101. ctx_valid = 0;
  102. if (!ctx_valid || (old_mm != mm)) {
  103. if (!ctx_valid)
  104. get_new_mmu_context(mm);
  105. load_secondary_context(mm);
  106. reload_tlbmiss_state(tsk, mm);
  107. }
  108. {
  109. unsigned long vm_mask = (1UL << cpu);
  110. /* Even if (mm == old_mm) we _must_ check
  111.  * the cpu_vm_mask.  If we do not we could
  112.  * corrupt the TLB state because of how
  113.  * smp_flush_tlb_{page,range,mm} on sparc64
  114.  * and lazy tlb switches work. -DaveM
  115.  */
  116. if (!ctx_valid || !(mm->cpu_vm_mask & vm_mask)) {
  117. mm->cpu_vm_mask |= vm_mask;
  118. __flush_tlb_mm(CTX_HWBITS(mm->context), SECONDARY_CONTEXT);
  119. }
  120. }
  121. spin_unlock(&mm->page_table_lock);
  122. }
  123. /* Activate a new MM instance for the current task. */
  124. static inline void activate_mm(struct mm_struct *active_mm, struct mm_struct *mm)
  125. {
  126. unsigned long vm_mask;
  127. spin_lock(&mm->page_table_lock);
  128. if (!CTX_VALID(mm->context))
  129. get_new_mmu_context(mm);
  130. vm_mask = (1UL << smp_processor_id());
  131. if (!(mm->cpu_vm_mask & vm_mask))
  132. mm->cpu_vm_mask |= vm_mask;
  133. spin_unlock(&mm->page_table_lock);
  134. load_secondary_context(mm);
  135. __flush_tlb_mm(CTX_HWBITS(mm->context), SECONDARY_CONTEXT);
  136. reload_tlbmiss_state(current, mm);
  137. }
  138. #endif /* !(__ASSEMBLY__) */
  139. #endif /* !(__SPARC64_MMU_CONTEXT_H) */