mmu_context.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #include <asm-generic/mm_hooks.h>
  21. void __check_kvm_seq(struct mm_struct *mm);
  22. #ifdef CONFIG_CPU_HAS_ASID
  23. /*
  24. * On ARMv6, we have the following structure in the Context ID:
  25. *
  26. * 31 7 0
  27. * +-------------------------+-----------+
  28. * | process ID | ASID |
  29. * +-------------------------+-----------+
  30. * | context ID |
  31. * +-------------------------------------+
  32. *
  33. * The ASID is used to tag entries in the CPU caches and TLBs.
  34. * The context ID is used by debuggers and trace logic, and
  35. * should be unique within all running processes.
  36. */
  37. #define ASID_BITS 8
  38. #define ASID_MASK ((~0) << ASID_BITS)
  39. #define ASID_FIRST_VERSION (1 << ASID_BITS)
  40. extern unsigned int cpu_last_asid;
  41. #ifdef CONFIG_SMP
  42. DECLARE_PER_CPU(struct mm_struct *, current_mm);
  43. #endif
  44. void __init_new_context(struct task_struct *tsk, struct mm_struct *mm);
  45. void __new_context(struct mm_struct *mm);
  46. static inline void check_context(struct mm_struct *mm)
  47. {
  48. /*
  49. * This code is executed with interrupts enabled. Therefore,
  50. * mm->context.id cannot be updated to the latest ASID version
  51. * on a different CPU (and condition below not triggered)
  52. * without first getting an IPI to reset the context. The
  53. * alternative is to take a read_lock on mm->context.id_lock
  54. * (after changing its type to rwlock_t).
  55. */
  56. if (unlikely((mm->context.id ^ cpu_last_asid) >> ASID_BITS))
  57. __new_context(mm);
  58. if (unlikely(mm->context.kvm_seq != init_mm.context.kvm_seq))
  59. __check_kvm_seq(mm);
  60. }
  61. #define init_new_context(tsk,mm) (__init_new_context(tsk,mm),0)
  62. #else
  63. static inline void check_context(struct mm_struct *mm)
  64. {
  65. #ifdef CONFIG_MMU
  66. if (unlikely(mm->context.kvm_seq != init_mm.context.kvm_seq))
  67. __check_kvm_seq(mm);
  68. #endif
  69. }
  70. #define init_new_context(tsk,mm) 0
  71. #endif
  72. #define destroy_context(mm) do { } while(0)
  73. /*
  74. * This is called when "tsk" is about to enter lazy TLB mode.
  75. *
  76. * mm: describes the currently active mm context
  77. * tsk: task which is entering lazy tlb
  78. * cpu: cpu number which is entering lazy tlb
  79. *
  80. * tsk->mm will be NULL
  81. */
  82. static inline void
  83. enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  84. {
  85. }
  86. /*
  87. * This is the actual mm switch as far as the scheduler
  88. * is concerned. No registers are touched. We avoid
  89. * calling the CPU specific function when the mm hasn't
  90. * actually changed.
  91. */
  92. static inline void
  93. switch_mm(struct mm_struct *prev, struct mm_struct *next,
  94. struct task_struct *tsk)
  95. {
  96. #ifdef CONFIG_MMU
  97. unsigned int cpu = smp_processor_id();
  98. #ifdef CONFIG_SMP
  99. /* check for possible thread migration */
  100. if (!cpumask_empty(mm_cpumask(next)) &&
  101. !cpumask_test_cpu(cpu, mm_cpumask(next)))
  102. __flush_icache_all();
  103. #endif
  104. if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) || prev != next) {
  105. #ifdef CONFIG_SMP
  106. struct mm_struct **crt_mm = &per_cpu(current_mm, cpu);
  107. *crt_mm = next;
  108. #endif
  109. check_context(next);
  110. cpu_switch_mm(next->pgd, next);
  111. if (cache_is_vivt())
  112. cpumask_clear_cpu(cpu, mm_cpumask(prev));
  113. }
  114. #endif
  115. }
  116. #define deactivate_mm(tsk,mm) do { } while (0)
  117. #define activate_mm(prev,next) switch_mm(prev, next, NULL)
  118. #endif