summaryrefslogtreecommitdiff
path: root/arch/mips/mm/context.c
blob: dcaceee179f7b3ff04be6e374ac413c25fdbe770 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-License-Identifier: GPL-2.0
#include <linux/mmu_context.h>

void get_new_mmu_context(struct mm_struct *mm)
{
	unsigned int cpu;
	u64 asid;

	cpu = smp_processor_id();
	asid = asid_cache(cpu);

	if (!((asid += cpu_asid_inc()) & cpu_asid_mask(&cpu_data[cpu]))) {
		if (cpu_has_vtag_icache)
			flush_icache_all();
		local_flush_tlb_all();	/* start new asid cycle */
	}

	set_cpu_context(cpu, mm, asid);
	asid_cache(cpu) = asid;
}

void check_mmu_context(struct mm_struct *mm)
{
	unsigned int cpu = smp_processor_id();

	/* Check if our ASID is of an older version and thus invalid */
	if ((cpu_context(cpu, mm) ^ asid_cache(cpu)) & asid_version_mask(cpu))
		get_new_mmu_context(mm);
}

void check_switch_mmu_context(struct mm_struct *mm)
{
	unsigned int cpu = smp_processor_id();

	check_mmu_context(mm);
	write_c0_entryhi(cpu_asid(cpu, mm));
	TLBMISS_HANDLER_SETUP_PGD(mm->pgd);
}