mmu_context.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * arch/arm/include/asm/mmu_context.h
  3. *
  4. * Copyright (C) 1996 Russell King.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Changelog:
  11. * 27-06-1996 RMK Created
  12. */
  13. #ifndef __ASM_ARM_MMU_CONTEXT_H
  14. #define __ASM_ARM_MMU_CONTEXT_H
  15. #include <linux/compiler.h>
  16. #include <linux/sched.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/cachetype.h>
  19. #include <asm/proc-fns.h>
  20. void __check_kvm_seq(struct mm_struct *mm);
  21. #ifdef CONFIG_CPU_HAS_ASID
  22. /*
  23. * On ARMv6, we have the following structure in the Context ID:
  24. *
  25. * 31 7 0
  26. * +-------------------------+-----------+
  27. * | process ID | ASID |
  28. * +-------------------------+-----------+
  29. * | context ID |
  30. * +-------------------------------------+
  31. *
  32. * The ASID is used to tag entries in the CPU caches and TLBs.
  33. * The context ID is used by debuggers and trace logic, and
  34. * should be unique within all running processes.
  35. */
  36. #define ASID_BITS 8
  37. #define ASID_MASK ((~0) << ASID_BITS)
  38. #define ASID_FIRST_VERSION (1 << ASID_BITS)
  39. extern unsigned int cpu_last_asid;
  40. #ifdef CONFIG_SMP
  41. DECLARE_PER_CPU(struct mm_struct *, current_mm);
  42. #endif
  43. void __init_new_context(struct task_struct *tsk, struct mm_struct *mm);
  44. void __new_context(struct mm_struct *mm);
  45. static inline void check_context(struct mm_struct *mm)
  46. {
  47. /*
  48. * This code is executed with interrupts enabled. Therefore,
  49. * mm->context.id cannot be updated to the latest ASID version
  50. * on a different CPU (and condition below not triggered)
  51. * without first getting an IPI to reset the context. The
  52. * alternative is to take a read_lock on mm->context.id_lock
  53. * (after changing its type to rwlock_t).
  54. */
  55. if (unlikely((mm->context.id ^ cpu_last_asid) >> ASID_BITS))
  56. __new_context(mm);
  57. if (unlikely(mm->context.kvm_seq != init_mm.context.kvm_seq))
  58. __check_kvm_seq(mm);
  59. }
  60. #define init_new_context(tsk,mm) (__init_new_context(tsk,mm),0)
  61. #else
  62. static inline void check_context(struct mm_struct *mm)
  63. {
  64. #ifdef CONFIG_MMU
  65. if (unlikely(mm->context.kvm_seq != init_mm.context.kvm_seq))
  66. __check_kvm_seq(mm);
  67. #endif
  68. }
  69. #define init_new_context(tsk,mm) 0
  70. #endif
  71. #define destroy_context(mm) do { } while(0)
  72. /*
  73. * This is called when "tsk" is about to enter lazy TLB mode.
  74. *
  75. * mm: describes the currently active mm context
  76. * tsk: task which is entering lazy tlb
  77. * cpu: cpu number which is entering lazy tlb
  78. *
  79. * tsk->mm will be NULL
  80. */
  81. static inline void
  82. enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  83. {
  84. }
  85. /*
  86. * This is the actual mm switch as far as the scheduler
  87. * is concerned. No registers are touched. We avoid
  88. * calling the CPU specific function when the mm hasn't
  89. * actually changed.
  90. */
  91. static inline void
  92. switch_mm(struct mm_struct *prev, struct mm_struct *next,
  93. struct task_struct *tsk)
  94. {
  95. #ifdef CONFIG_MMU
  96. unsigned int cpu = smp_processor_id();
  97. #ifdef CONFIG_SMP
  98. /* check for possible thread migration */
  99. if (!cpumask_empty(mm_cpumask(next)) &&
  100. !cpumask_test_cpu(cpu, mm_cpumask(next)))
  101. __flush_icache_all();
  102. #endif
  103. if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) || prev != next) {
  104. #ifdef CONFIG_SMP
  105. struct mm_struct **crt_mm = &per_cpu(current_mm, cpu);
  106. *crt_mm = next;
  107. #endif
  108. check_context(next);
  109. cpu_switch_mm(next->pgd, next);
  110. if (cache_is_vivt())
  111. cpumask_clear_cpu(cpu, mm_cpumask(prev));
  112. }
  113. #endif
  114. }
  115. #define deactivate_mm(tsk,mm) do { } while (0)
  116. #define activate_mm(prev,next) switch_mm(prev, next, NULL)
  117. /*
  118. * We are inserting a "fake" vma for the user-accessible vector page so
  119. * gdb and friends can get to it through ptrace and /proc/<pid>/mem.
  120. * But we also want to remove it before the generic code gets to see it
  121. * during process exit or the unmapping of it would cause total havoc.
  122. * (the macro is used as remove_vma() is static to mm/mmap.c)
  123. */
  124. #define arch_exit_mmap(mm) \
  125. do { \
  126. struct vm_area_struct *high_vma = find_vma(mm, 0xffff0000); \
  127. if (high_vma) { \
  128. BUG_ON(high_vma->vm_next); /* it should be last */ \
  129. if (high_vma->vm_prev) \
  130. high_vma->vm_prev->vm_next = NULL; \
  131. else \
  132. mm->mmap = NULL; \
  133. rb_erase(&high_vma->vm_rb, &mm->mm_rb); \
  134. mm->mmap_cache = NULL; \
  135. mm->map_count--; \
  136. remove_vma(high_vma); \
  137. } \
  138. } while (0)
  139. static inline void arch_dup_mmap(struct mm_struct *oldmm,
  140. struct mm_struct *mm)
  141. {
  142. }
  143. #endif