mmu_context.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * S390 version
  3. *
  4. * Derived from "include/asm-i386/mmu_context.h"
  5. */
  6. #ifndef __S390_MMU_CONTEXT_H
  7. #define __S390_MMU_CONTEXT_H
  8. #include <asm/pgalloc.h>
  9. #include <asm/uaccess.h>
  10. #include <asm/tlbflush.h>
  11. #include <asm/ctl_reg.h>
  12. static inline int init_new_context(struct task_struct *tsk,
  13. struct mm_struct *mm)
  14. {
  15. cpumask_clear(&mm->context.cpu_attach_mask);
  16. atomic_set(&mm->context.attach_count, 0);
  17. mm->context.flush_mm = 0;
  18. mm->context.asce_bits = _ASCE_TABLE_LENGTH | _ASCE_USER_BITS;
  19. #ifdef CONFIG_64BIT
  20. mm->context.asce_bits |= _ASCE_TYPE_REGION3;
  21. #endif
  22. mm->context.has_pgste = 0;
  23. mm->context.asce_limit = STACK_TOP_MAX;
  24. crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
  25. return 0;
  26. }
  27. #define destroy_context(mm) do { } while (0)
  28. static inline void update_user_asce(struct mm_struct *mm, int load_primary)
  29. {
  30. pgd_t *pgd = mm->pgd;
  31. S390_lowcore.user_asce = mm->context.asce_bits | __pa(pgd);
  32. if (load_primary)
  33. __ctl_load(S390_lowcore.user_asce, 1, 1);
  34. set_fs(current->thread.mm_segment);
  35. }
  36. static inline void clear_user_asce(struct mm_struct *mm, int load_primary)
  37. {
  38. S390_lowcore.user_asce = S390_lowcore.kernel_asce;
  39. if (load_primary)
  40. __ctl_load(S390_lowcore.user_asce, 1, 1);
  41. __ctl_load(S390_lowcore.user_asce, 7, 7);
  42. }
  43. static inline void update_primary_asce(struct task_struct *tsk)
  44. {
  45. unsigned long asce;
  46. __ctl_store(asce, 1, 1);
  47. if (asce != S390_lowcore.kernel_asce)
  48. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  49. set_tsk_thread_flag(tsk, TIF_ASCE);
  50. }
  51. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  52. struct task_struct *tsk)
  53. {
  54. int cpu = smp_processor_id();
  55. update_primary_asce(tsk);
  56. if (prev == next)
  57. return;
  58. if (MACHINE_HAS_TLB_LC)
  59. cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
  60. if (atomic_inc_return(&next->context.attach_count) >> 16) {
  61. /* Delay update_user_asce until all TLB flushes are done. */
  62. set_tsk_thread_flag(tsk, TIF_TLB_WAIT);
  63. /* Clear old ASCE by loading the kernel ASCE. */
  64. clear_user_asce(next, 0);
  65. } else {
  66. cpumask_set_cpu(cpu, mm_cpumask(next));
  67. update_user_asce(next, 0);
  68. if (next->context.flush_mm)
  69. /* Flush pending TLBs */
  70. __tlb_flush_mm(next);
  71. }
  72. atomic_dec(&prev->context.attach_count);
  73. WARN_ON(atomic_read(&prev->context.attach_count) < 0);
  74. if (MACHINE_HAS_TLB_LC)
  75. cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
  76. }
  77. #define finish_arch_post_lock_switch finish_arch_post_lock_switch
  78. static inline void finish_arch_post_lock_switch(void)
  79. {
  80. struct task_struct *tsk = current;
  81. struct mm_struct *mm = tsk->mm;
  82. if (!test_tsk_thread_flag(tsk, TIF_TLB_WAIT))
  83. return;
  84. preempt_disable();
  85. clear_tsk_thread_flag(tsk, TIF_TLB_WAIT);
  86. while (atomic_read(&mm->context.attach_count) >> 16)
  87. cpu_relax();
  88. cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
  89. update_user_asce(mm, 0);
  90. if (mm->context.flush_mm)
  91. __tlb_flush_mm(mm);
  92. preempt_enable();
  93. }
  94. #define enter_lazy_tlb(mm,tsk) do { } while (0)
  95. #define deactivate_mm(tsk,mm) do { } while (0)
  96. static inline void activate_mm(struct mm_struct *prev,
  97. struct mm_struct *next)
  98. {
  99. switch_mm(prev, next, current);
  100. }
  101. static inline void arch_dup_mmap(struct mm_struct *oldmm,
  102. struct mm_struct *mm)
  103. {
  104. #ifdef CONFIG_64BIT
  105. if (oldmm->context.asce_limit < mm->context.asce_limit)
  106. crst_table_downgrade(mm, oldmm->context.asce_limit);
  107. #endif
  108. }
  109. static inline void arch_exit_mmap(struct mm_struct *mm)
  110. {
  111. }
  112. #endif /* __S390_MMU_CONTEXT_H */