context.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
  3. #include <linux/bitops.h>
  4. #include <linux/sched.h>
  5. #include <linux/slab.h>
  6. #include <linux/mm.h>
  7. #include <asm/asid.h>
  8. #include <asm/mmu_context.h>
  9. #include <asm/smp.h>
  10. #include <asm/tlbflush.h>
  11. static DEFINE_PER_CPU(atomic64_t, active_asids);
  12. static DEFINE_PER_CPU(u64, reserved_asids);
  13. struct asid_info asid_info;
  14. void check_and_switch_context(struct mm_struct *mm, unsigned int cpu)
  15. {
  16. asid_check_context(&asid_info, &mm->context.asid, cpu, mm);
  17. }
  18. static void asid_flush_cpu_ctxt(void)
  19. {
  20. local_tlb_invalid_all();
  21. }
  22. static int asids_init(void)
  23. {
  24. BUG_ON(((1 << CONFIG_CPU_ASID_BITS) - 1) <= num_possible_cpus());
  25. if (asid_allocator_init(&asid_info, CONFIG_CPU_ASID_BITS, 1,
  26. asid_flush_cpu_ctxt))
  27. panic("Unable to initialize ASID allocator for %lu ASIDs\n",
  28. NUM_ASIDS(&asid_info));
  29. asid_info.active = &active_asids;
  30. asid_info.reserved = &reserved_asids;
  31. pr_info("ASID allocator initialised with %lu entries\n",
  32. NUM_CTXT_ASIDS(&asid_info));
  33. return 0;
  34. }
  35. early_initcall(asids_init);