mmu_context.h 4.6 KB

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