1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <linux/mm.h>
4 #include <linux/smp.h>
5 #include <asm/sbi.h>
6 
flush_tlb_all(void)7 void flush_tlb_all(void)
8 {
9 	sbi_remote_sfence_vma(NULL, 0, -1);
10 }
11 
__sbi_tlb_flush_range(struct cpumask * cmask,unsigned long start,unsigned long size)12 static void __sbi_tlb_flush_range(struct cpumask *cmask, unsigned long start,
13 				  unsigned long size)
14 {
15 	struct cpumask hmask;
16 
17 	riscv_cpuid_to_hartid_mask(cmask, &hmask);
18 	sbi_remote_sfence_vma(hmask.bits, start, size);
19 }
20 
flush_tlb_mm(struct mm_struct * mm)21 void flush_tlb_mm(struct mm_struct *mm)
22 {
23 	__sbi_tlb_flush_range(mm_cpumask(mm), 0, -1);
24 }
25 
flush_tlb_page(struct vm_area_struct * vma,unsigned long addr)26 void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
27 {
28 	__sbi_tlb_flush_range(mm_cpumask(vma->vm_mm), addr, PAGE_SIZE);
29 }
30 
flush_tlb_range(struct vm_area_struct * vma,unsigned long start,unsigned long end)31 void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
32 		     unsigned long end)
33 {
34 	__sbi_tlb_flush_range(mm_cpumask(vma->vm_mm), start, end - start);
35 }
36