1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2009 Chen Liqin <liqin.chen@sunplusct.com>
4 * Copyright (C) 2012 Regents of the University of California
7 #ifndef _ASM_RISCV_TLBFLUSH_H
8 #define _ASM_RISCV_TLBFLUSH_H
10 #include <linux/mm_types.h>
14 * Flush entire local TLB. 'sfence.vma' implicitly fences with the instruction
15 * cache as well, so a 'fence.i' is not necessary.
17 static inline void local_flush_tlb_all(void)
19 __asm__ __volatile__ ("sfence.vma" : : : "memory");
22 /* Flush one page from local TLB */
23 static inline void local_flush_tlb_page(unsigned long addr)
25 __asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory");
30 #define flush_tlb_all() local_flush_tlb_all()
31 #define flush_tlb_page(vma, addr) local_flush_tlb_page(addr)
33 static inline void flush_tlb_range(struct vm_area_struct *vma,
34 unsigned long start, unsigned long end)
36 local_flush_tlb_all();
39 #define flush_tlb_mm(mm) flush_tlb_all()
41 #else /* CONFIG_SMP */
45 static inline void remote_sfence_vma(struct cpumask *cmask, unsigned long start,
50 cpumask_clear(&hmask);
51 riscv_cpuid_to_hartid_mask(cmask, &hmask);
52 sbi_remote_sfence_vma(hmask.bits, start, size);
55 #define flush_tlb_all() sbi_remote_sfence_vma(NULL, 0, -1)
57 #define flush_tlb_range(vma, start, end) \
58 remote_sfence_vma(mm_cpumask((vma)->vm_mm), start, (end) - (start))
60 static inline void flush_tlb_page(struct vm_area_struct *vma,
63 flush_tlb_range(vma, addr, addr + PAGE_SIZE);
66 #define flush_tlb_mm(mm) \
67 remote_sfence_vma(mm_cpumask(mm), 0, -1)
69 #endif /* CONFIG_SMP */
71 /* Flush a range of kernel pages */
72 static inline void flush_tlb_kernel_range(unsigned long start,
78 #endif /* _ASM_RISCV_TLBFLUSH_H */