Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
0003 
0004 #include <linux/bitops.h>
0005 #include <linux/sched.h>
0006 #include <linux/slab.h>
0007 #include <linux/mm.h>
0008 
0009 #include <asm/asid.h>
0010 #include <asm/mmu_context.h>
0011 #include <asm/smp.h>
0012 #include <asm/tlbflush.h>
0013 
0014 static DEFINE_PER_CPU(atomic64_t, active_asids);
0015 static DEFINE_PER_CPU(u64, reserved_asids);
0016 
0017 struct asid_info asid_info;
0018 
0019 void check_and_switch_context(struct mm_struct *mm, unsigned int cpu)
0020 {
0021     asid_check_context(&asid_info, &mm->context.asid, cpu, mm);
0022 }
0023 
0024 static void asid_flush_cpu_ctxt(void)
0025 {
0026     local_tlb_invalid_all();
0027 }
0028 
0029 static int asids_init(void)
0030 {
0031     BUG_ON(((1 << CONFIG_CPU_ASID_BITS) - 1) <= num_possible_cpus());
0032 
0033     if (asid_allocator_init(&asid_info, CONFIG_CPU_ASID_BITS, 1,
0034                 asid_flush_cpu_ctxt))
0035         panic("Unable to initialize ASID allocator for %lu ASIDs\n",
0036               NUM_ASIDS(&asid_info));
0037 
0038     asid_info.active = &active_asids;
0039     asid_info.reserved = &reserved_asids;
0040 
0041     pr_info("ASID allocator initialised with %lu entries\n",
0042         NUM_CTXT_ASIDS(&asid_info));
0043 
0044     return 0;
0045 }
0046 early_initcall(asids_init);