mmu_context.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. mm->context.asce_bits |= _ASCE_TYPE_REGION3;
  20. #ifdef CONFIG_PGSTE
  21. mm->context.alloc_pgste = page_table_allocate_pgste;
  22. mm->context.has_pgste = 0;
  23. mm->context.use_skey = 0;
  24. #endif
  25. mm->context.asce_limit = STACK_TOP_MAX;
  26. crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
  27. return 0;
  28. }
  29. #define destroy_context(mm) do { } while (0)
  30. static inline void set_user_asce(struct mm_struct *mm)
  31. {
  32. S390_lowcore.user_asce = mm->context.asce_bits | __pa(mm->pgd);
  33. if (current->thread.mm_segment.ar4)
  34. __ctl_load(S390_lowcore.user_asce, 7, 7);
  35. set_cpu_flag(CIF_ASCE);
  36. }
  37. static inline void clear_user_asce(void)
  38. {
  39. S390_lowcore.user_asce = S390_lowcore.kernel_asce;
  40. __ctl_load(S390_lowcore.user_asce, 1, 1);
  41. __ctl_load(S390_lowcore.user_asce, 7, 7);
  42. }
  43. static inline void load_kernel_asce(void)
  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_cpu_flag(CIF_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. S390_lowcore.user_asce = next->context.asce_bits | __pa(next->pgd);
  56. if (prev == next)
  57. return;
  58. if (MACHINE_HAS_TLB_LC)
  59. cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
  60. /* Clear old ASCE by loading the kernel ASCE. */
  61. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  62. __ctl_load(S390_lowcore.kernel_asce, 7, 7);
  63. atomic_inc(&next->context.attach_count);
  64. atomic_dec(&prev->context.attach_count);
  65. if (MACHINE_HAS_TLB_LC)
  66. cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
  67. }
  68. #define finish_arch_post_lock_switch finish_arch_post_lock_switch
  69. static inline void finish_arch_post_lock_switch(void)
  70. {
  71. struct task_struct *tsk = current;
  72. struct mm_struct *mm = tsk->mm;
  73. load_kernel_asce();
  74. if (mm) {
  75. preempt_disable();
  76. while (atomic_read(&mm->context.attach_count) >> 16)
  77. cpu_relax();
  78. cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
  79. if (mm->context.flush_mm)
  80. __tlb_flush_mm(mm);
  81. preempt_enable();
  82. }
  83. set_fs(current->thread.mm_segment);
  84. }
  85. #define enter_lazy_tlb(mm,tsk) do { } while (0)
  86. #define deactivate_mm(tsk,mm) do { } while (0)
  87. static inline void activate_mm(struct mm_struct *prev,
  88. struct mm_struct *next)
  89. {
  90. switch_mm(prev, next, current);
  91. cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
  92. set_user_asce(next);
  93. }
  94. static inline void arch_dup_mmap(struct mm_struct *oldmm,
  95. struct mm_struct *mm)
  96. {
  97. if (oldmm->context.asce_limit < mm->context.asce_limit)
  98. crst_table_downgrade(mm, oldmm->context.asce_limit);
  99. }
  100. static inline void arch_exit_mmap(struct mm_struct *mm)
  101. {
  102. }
  103. static inline void arch_unmap(struct mm_struct *mm,
  104. struct vm_area_struct *vma,
  105. unsigned long start, unsigned long end)
  106. {
  107. }
  108. static inline void arch_bprm_mm_init(struct mm_struct *mm,
  109. struct vm_area_struct *vma)
  110. {
  111. }
  112. #endif /* __S390_MMU_CONTEXT_H */