xref: /openbmc/linux/arch/riscv/include/asm/tlbflush.h (revision 2a12187d)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2009 Chen Liqin <liqin.chen@sunplusct.com>
4  * Copyright (C) 2012 Regents of the University of California
5  */
6 
7 #ifndef _ASM_RISCV_TLBFLUSH_H
8 #define _ASM_RISCV_TLBFLUSH_H
9 
10 #include <linux/mm_types.h>
11 #include <asm/smp.h>
12 #include <asm/errata_list.h>
13 
14 #ifdef CONFIG_MMU
15 static inline void local_flush_tlb_all(void)
16 {
17 	__asm__ __volatile__ ("sfence.vma" : : : "memory");
18 }
19 
20 /* Flush one page from local TLB */
21 static inline void local_flush_tlb_page(unsigned long addr)
22 {
23 	ALT_FLUSH_TLB_PAGE(__asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory"));
24 }
25 
26 static inline void local_flush_tlb_all_asid(unsigned long asid)
27 {
28 	__asm__ __volatile__ ("sfence.vma x0, %0"
29 			:
30 			: "r" (asid)
31 			: "memory");
32 }
33 
34 static inline void local_flush_tlb_page_asid(unsigned long addr,
35 		unsigned long asid)
36 {
37 	__asm__ __volatile__ ("sfence.vma %0, %1"
38 			:
39 			: "r" (addr), "r" (asid)
40 			: "memory");
41 }
42 
43 #else /* CONFIG_MMU */
44 #define local_flush_tlb_all()			do { } while (0)
45 #define local_flush_tlb_page(addr)		do { } while (0)
46 #endif /* CONFIG_MMU */
47 
48 #if defined(CONFIG_SMP) && defined(CONFIG_MMU)
49 void flush_tlb_all(void);
50 void flush_tlb_mm(struct mm_struct *mm);
51 void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr);
52 void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
53 		     unsigned long end);
54 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
55 #define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE
56 void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start,
57 			unsigned long end);
58 #endif
59 #else /* CONFIG_SMP && CONFIG_MMU */
60 
61 #define flush_tlb_all() local_flush_tlb_all()
62 #define flush_tlb_page(vma, addr) local_flush_tlb_page(addr)
63 
64 static inline void flush_tlb_range(struct vm_area_struct *vma,
65 		unsigned long start, unsigned long end)
66 {
67 	local_flush_tlb_all();
68 }
69 
70 #define flush_tlb_mm(mm) flush_tlb_all()
71 #endif /* !CONFIG_SMP || !CONFIG_MMU */
72 
73 /* Flush a range of kernel pages */
74 static inline void flush_tlb_kernel_range(unsigned long start,
75 	unsigned long end)
76 {
77 	flush_tlb_all();
78 }
79 
80 #endif /* _ASM_RISCV_TLBFLUSH_H */
81