mmu_context.h 3.0 KB

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