mmu_context.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * linux/include/asm-arm/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/proc-fns.h>
  18. #include <asm-generic/mm_hooks.h>
  19. void __check_kvm_seq(struct mm_struct *mm);
  20. #ifdef CONFIG_CPU_HAS_ASID
  21. /*
  22. * On ARMv6, we have the following structure in the Context ID:
  23. *
  24. * 31 7 0
  25. * +-------------------------+-----------+
  26. * | process ID | ASID |
  27. * +-------------------------+-----------+
  28. * | context ID |
  29. * +-------------------------------------+
  30. *
  31. * The ASID is used to tag entries in the CPU caches and TLBs.
  32. * The context ID is used by debuggers and trace logic, and
  33. * should be unique within all running processes.
  34. */
  35. #define ASID_BITS 8
  36. #define ASID_MASK ((~0) << ASID_BITS)
  37. #define ASID_FIRST_VERSION (1 << ASID_BITS)
  38. extern unsigned int cpu_last_asid;
  39. void __init_new_context(struct task_struct *tsk, struct mm_struct *mm);
  40. void __new_context(struct mm_struct *mm);
  41. static inline void check_context(struct mm_struct *mm)
  42. {
  43. if (unlikely((mm->context.id ^ cpu_last_asid) >> ASID_BITS))
  44. __new_context(mm);
  45. if (unlikely(mm->context.kvm_seq != init_mm.context.kvm_seq))
  46. __check_kvm_seq(mm);
  47. }
  48. #define init_new_context(tsk,mm) (__init_new_context(tsk,mm),0)
  49. #else
  50. static inline void check_context(struct mm_struct *mm)
  51. {
  52. if (unlikely(mm->context.kvm_seq != init_mm.context.kvm_seq))
  53. __check_kvm_seq(mm);
  54. }
  55. #define init_new_context(tsk,mm) 0
  56. #endif
  57. #define destroy_context(mm) do { } while(0)
  58. /*
  59. * This is called when "tsk" is about to enter lazy TLB mode.
  60. *
  61. * mm: describes the currently active mm context
  62. * tsk: task which is entering lazy tlb
  63. * cpu: cpu number which is entering lazy tlb
  64. *
  65. * tsk->mm will be NULL
  66. */
  67. static inline void
  68. enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  69. {
  70. }
  71. /*
  72. * This is the actual mm switch as far as the scheduler
  73. * is concerned. No registers are touched. We avoid
  74. * calling the CPU specific function when the mm hasn't
  75. * actually changed.
  76. */
  77. static inline void
  78. switch_mm(struct mm_struct *prev, struct mm_struct *next,
  79. struct task_struct *tsk)
  80. {
  81. #ifdef CONFIG_MMU
  82. unsigned int cpu = smp_processor_id();
  83. if (!cpu_test_and_set(cpu, next->cpu_vm_mask) || prev != next) {
  84. check_context(next);
  85. cpu_switch_mm(next->pgd, next);
  86. if (cache_is_vivt())
  87. cpu_clear(cpu, prev->cpu_vm_mask);
  88. }
  89. #endif
  90. }
  91. #define deactivate_mm(tsk,mm) do { } while (0)
  92. #define activate_mm(prev,next) switch_mm(prev, next, NULL)
  93. #endif