xref: /openbmc/linux/arch/riscv/include/asm/tlbflush.h (revision 586b4106)
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 #define FLUSH_TLB_MAX_SIZE      ((unsigned long)-1)
15 #define FLUSH_TLB_NO_ASID       ((unsigned long)-1)
16 
17 #ifdef CONFIG_MMU
18 extern unsigned long asid_mask;
19 
20 static inline void local_flush_tlb_all(void)
21 {
22 	__asm__ __volatile__ ("sfence.vma" : : : "memory");
23 }
24 
25 static inline void local_flush_tlb_all_asid(unsigned long asid)
26 {
27 	if (asid != FLUSH_TLB_NO_ASID)
28 		ALT_SFENCE_VMA_ASID(asid);
29 	else
30 		local_flush_tlb_all();
31 }
32 
33 /* Flush one page from local TLB */
34 static inline void local_flush_tlb_page(unsigned long addr)
35 {
36 	ALT_SFENCE_VMA_ADDR(addr);
37 }
38 
39 static inline void local_flush_tlb_page_asid(unsigned long addr,
40 					     unsigned long asid)
41 {
42 	if (asid != FLUSH_TLB_NO_ASID)
43 		ALT_SFENCE_VMA_ADDR_ASID(addr, asid);
44 	else
45 		local_flush_tlb_page(addr);
46 }
47 #else /* CONFIG_MMU */
48 #define local_flush_tlb_all()			do { } while (0)
49 #define local_flush_tlb_page(addr)		do { } while (0)
50 #endif /* CONFIG_MMU */
51 
52 #if defined(CONFIG_SMP) && defined(CONFIG_MMU)
53 void flush_tlb_all(void);
54 void flush_tlb_mm(struct mm_struct *mm);
55 void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
56 			unsigned long end, unsigned int page_size);
57 void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr);
58 void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
59 		     unsigned long end);
60 void flush_tlb_kernel_range(unsigned long start, unsigned long end);
61 void local_flush_tlb_kernel_range(unsigned long start, unsigned long end);
62 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63 #define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE
64 void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start,
65 			unsigned long end);
66 #endif
67 #else /* CONFIG_SMP && CONFIG_MMU */
68 
69 #define flush_tlb_all() local_flush_tlb_all()
70 #define flush_tlb_page(vma, addr) local_flush_tlb_page(addr)
71 
72 static inline void flush_tlb_range(struct vm_area_struct *vma,
73 		unsigned long start, unsigned long end)
74 {
75 	local_flush_tlb_all();
76 }
77 
78 /* Flush a range of kernel pages */
79 static inline void flush_tlb_kernel_range(unsigned long start,
80 	unsigned long end)
81 {
82 	local_flush_tlb_all();
83 }
84 
85 #define flush_tlb_mm(mm) flush_tlb_all()
86 #define flush_tlb_mm_range(mm, start, end, page_size) flush_tlb_all()
87 #define local_flush_tlb_kernel_range(start, end) flush_tlb_all()
88 #endif /* !CONFIG_SMP || !CONFIG_MMU */
89 
90 #endif /* _ASM_RISCV_TLBFLUSH_H */
91