mmu_context.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.use_skey = 0;
  24. mm->context.asce_limit = STACK_TOP_MAX;
  25. crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
  26. return 0;
  27. }
  28. #define destroy_context(mm) do { } while (0)
  29. static inline void set_user_asce(struct mm_struct *mm)
  30. {
  31. S390_lowcore.user_asce = mm->context.asce_bits | __pa(mm->pgd);
  32. if (current->thread.mm_segment.ar4)
  33. __ctl_load(S390_lowcore.user_asce, 7, 7);
  34. set_cpu_flag(CIF_ASCE);
  35. }
  36. static inline void clear_user_asce(void)
  37. {
  38. S390_lowcore.user_asce = S390_lowcore.kernel_asce;
  39. __ctl_load(S390_lowcore.user_asce, 1, 1);
  40. __ctl_load(S390_lowcore.user_asce, 7, 7);
  41. }
  42. static inline void load_kernel_asce(void)
  43. {
  44. unsigned long asce;
  45. __ctl_store(asce, 1, 1);
  46. if (asce != S390_lowcore.kernel_asce)
  47. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  48. set_cpu_flag(CIF_ASCE);
  49. }
  50. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  51. struct task_struct *tsk)
  52. {
  53. int cpu = smp_processor_id();
  54. if (prev == next)
  55. return;
  56. if (MACHINE_HAS_TLB_LC)
  57. cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
  58. /* Clear old ASCE by loading the kernel ASCE. */
  59. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  60. __ctl_load(S390_lowcore.kernel_asce, 7, 7);
  61. atomic_inc(&next->context.attach_count);
  62. atomic_dec(&prev->context.attach_count);
  63. if (MACHINE_HAS_TLB_LC)
  64. cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
  65. S390_lowcore.user_asce = next->context.asce_bits | __pa(next->pgd);
  66. }
  67. #define finish_arch_post_lock_switch finish_arch_post_lock_switch
  68. static inline void finish_arch_post_lock_switch(void)
  69. {
  70. struct task_struct *tsk = current;
  71. struct mm_struct *mm = tsk->mm;
  72. load_kernel_asce();
  73. if (mm) {
  74. preempt_disable();
  75. while (atomic_read(&mm->context.attach_count) >> 16)
  76. cpu_relax();
  77. cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
  78. if (mm->context.flush_mm)
  79. __tlb_flush_mm(mm);
  80. preempt_enable();
  81. }
  82. set_fs(current->thread.mm_segment);
  83. }
  84. #define enter_lazy_tlb(mm,tsk) do { } while (0)
  85. #define deactivate_mm(tsk,mm) do { } while (0)
  86. static inline void activate_mm(struct mm_struct *prev,
  87. struct mm_struct *next)
  88. {
  89. switch_mm(prev, next, current);
  90. cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
  91. set_user_asce(next);
  92. }
  93. static inline void arch_dup_mmap(struct mm_struct *oldmm,
  94. struct mm_struct *mm)
  95. {
  96. #ifdef CONFIG_64BIT
  97. if (oldmm->context.asce_limit < mm->context.asce_limit)
  98. crst_table_downgrade(mm, oldmm->context.asce_limit);
  99. #endif
  100. }
  101. static inline void arch_exit_mmap(struct mm_struct *mm)
  102. {
  103. }
  104. #endif /* __S390_MMU_CONTEXT_H */