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 13 /* 14 * Flush entire local TLB. 'sfence.vma' implicitly fences with the instruction 15 * cache as well, so a 'fence.i' is not necessary. 16 */ 17 static inline void local_flush_tlb_all(void) 18 { 19 __asm__ __volatile__ ("sfence.vma" : : : "memory"); 20 } 21 22 /* Flush one page from local TLB */ 23 static inline void local_flush_tlb_page(unsigned long addr) 24 { 25 __asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory"); 26 } 27 28 #ifdef CONFIG_SMP 29 void flush_tlb_all(void); 30 void flush_tlb_mm(struct mm_struct *mm); 31 void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr); 32 void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, 33 unsigned long end); 34 #else /* CONFIG_SMP */ 35 #define flush_tlb_all() local_flush_tlb_all() 36 #define flush_tlb_page(vma, addr) local_flush_tlb_page(addr) 37 38 static inline void flush_tlb_range(struct vm_area_struct *vma, 39 unsigned long start, unsigned long end) 40 { 41 local_flush_tlb_all(); 42 } 43 44 #define flush_tlb_mm(mm) flush_tlb_all() 45 #endif /* CONFIG_SMP */ 46 47 /* Flush a range of kernel pages */ 48 static inline void flush_tlb_kernel_range(unsigned long start, 49 unsigned long end) 50 { 51 flush_tlb_all(); 52 } 53 54 #endif /* _ASM_RISCV_TLBFLUSH_H */ 55