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