mmu_context.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2005-2017 Andes Technology Corporation
  3. #ifndef __ASM_NDS32_MMU_CONTEXT_H
  4. #define __ASM_NDS32_MMU_CONTEXT_H
  5. #include <linux/spinlock.h>
  6. #include <asm/tlbflush.h>
  7. #include <asm/proc-fns.h>
  8. #include <asm-generic/mm_hooks.h>
  9. static inline int
  10. init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  11. {
  12. mm->context.id = 0;
  13. return 0;
  14. }
  15. #define destroy_context(mm) do { } while(0)
  16. #define CID_BITS 9
  17. extern spinlock_t cid_lock;
  18. extern unsigned int cpu_last_cid;
  19. static inline void __new_context(struct mm_struct *mm)
  20. {
  21. unsigned int cid;
  22. unsigned long flags;
  23. spin_lock_irqsave(&cid_lock, flags);
  24. cid = cpu_last_cid;
  25. cpu_last_cid += 1 << TLB_MISC_offCID;
  26. if (cpu_last_cid == 0)
  27. cpu_last_cid = 1 << TLB_MISC_offCID << CID_BITS;
  28. if ((cid & TLB_MISC_mskCID) == 0)
  29. flush_tlb_all();
  30. spin_unlock_irqrestore(&cid_lock, flags);
  31. mm->context.id = cid;
  32. }
  33. static inline void check_context(struct mm_struct *mm)
  34. {
  35. if (unlikely
  36. ((mm->context.id ^ cpu_last_cid) >> TLB_MISC_offCID >> CID_BITS))
  37. __new_context(mm);
  38. }
  39. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  40. {
  41. }
  42. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  43. struct task_struct *tsk)
  44. {
  45. unsigned int cpu = smp_processor_id();
  46. if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) || prev != next) {
  47. check_context(next);
  48. cpu_switch_mm(next);
  49. }
  50. }
  51. #define deactivate_mm(tsk,mm) do { } while (0)
  52. #define activate_mm(prev,next) switch_mm(prev, next, NULL)
  53. #endif