mmu_context.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. void __init_new_context(struct task_struct *tsk, struct mm_struct *mm);
  42. void __new_context(struct mm_struct *mm);
  43. static inline void check_context(struct mm_struct *mm)
  44. {
  45. if (unlikely((mm->context.id ^ cpu_last_asid) >> ASID_BITS))
  46. __new_context(mm);
  47. if (unlikely(mm->context.kvm_seq != init_mm.context.kvm_seq))
  48. __check_kvm_seq(mm);
  49. }
  50. #define init_new_context(tsk,mm) (__init_new_context(tsk,mm),0)
  51. #else
  52. static inline void check_context(struct mm_struct *mm)
  53. {
  54. if (unlikely(mm->context.kvm_seq != init_mm.context.kvm_seq))
  55. __check_kvm_seq(mm);
  56. }
  57. #define init_new_context(tsk,mm) 0
  58. #endif
  59. #define destroy_context(mm) do { } while(0)
  60. /*
  61. * This is called when "tsk" is about to enter lazy TLB mode.
  62. *
  63. * mm: describes the currently active mm context
  64. * tsk: task which is entering lazy tlb
  65. * cpu: cpu number which is entering lazy tlb
  66. *
  67. * tsk->mm will be NULL
  68. */
  69. static inline void
  70. enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  71. {
  72. }
  73. /*
  74. * This is the actual mm switch as far as the scheduler
  75. * is concerned. No registers are touched. We avoid
  76. * calling the CPU specific function when the mm hasn't
  77. * actually changed.
  78. */
  79. static inline void
  80. switch_mm(struct mm_struct *prev, struct mm_struct *next,
  81. struct task_struct *tsk)
  82. {
  83. #ifdef CONFIG_MMU
  84. unsigned int cpu = smp_processor_id();
  85. #ifdef CONFIG_SMP
  86. /* check for possible thread migration */
  87. if (!cpus_empty(next->cpu_vm_mask) && !cpu_isset(cpu, next->cpu_vm_mask))
  88. __flush_icache_all();
  89. #endif
  90. if (!cpu_test_and_set(cpu, next->cpu_vm_mask) || prev != next) {
  91. check_context(next);
  92. cpu_switch_mm(next->pgd, next);
  93. if (cache_is_vivt())
  94. cpu_clear(cpu, prev->cpu_vm_mask);
  95. }
  96. #endif
  97. }
  98. #define deactivate_mm(tsk,mm) do { } while (0)
  99. #define activate_mm(prev,next) switch_mm(prev, next, NULL)
  100. #endif