Palmer Dabbelt | fab957c | 2017-07-10 18:02:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 Chen Liqin <liqin.chen@sunplusct.com> |
| 3 | * Copyright (C) 2012 Regents of the University of California |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation, version 2. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #ifndef _ASM_RISCV_TLBFLUSH_H |
| 16 | #define _ASM_RISCV_TLBFLUSH_H |
| 17 | |
Andrew Waterman | 08f051e | 2017-10-25 14:30:32 -0700 | [diff] [blame] | 18 | #include <linux/mm_types.h> |
| 19 | |
Palmer Dabbelt | c901e45 | 2017-11-28 14:06:17 -0800 | [diff] [blame] | 20 | /* |
| 21 | * Flush entire local TLB. 'sfence.vma' implicitly fences with the instruction |
| 22 | * cache as well, so a 'fence.i' is not necessary. |
| 23 | */ |
Palmer Dabbelt | fab957c | 2017-07-10 18:02:19 -0700 | [diff] [blame] | 24 | static inline void local_flush_tlb_all(void) |
| 25 | { |
| 26 | __asm__ __volatile__ ("sfence.vma" : : : "memory"); |
| 27 | } |
| 28 | |
| 29 | /* Flush one page from local TLB */ |
| 30 | static inline void local_flush_tlb_page(unsigned long addr) |
| 31 | { |
| 32 | __asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory"); |
| 33 | } |
| 34 | |
| 35 | #ifndef CONFIG_SMP |
| 36 | |
| 37 | #define flush_tlb_all() local_flush_tlb_all() |
| 38 | #define flush_tlb_page(vma, addr) local_flush_tlb_page(addr) |
Andrew Waterman | f1b65f2 | 2017-10-26 01:53:40 -0700 | [diff] [blame] | 39 | |
| 40 | static inline void flush_tlb_range(struct vm_area_struct *vma, |
| 41 | unsigned long start, unsigned long end) |
| 42 | { |
| 43 | local_flush_tlb_all(); |
| 44 | } |
| 45 | |
| 46 | #define flush_tlb_mm(mm) flush_tlb_all() |
Palmer Dabbelt | fab957c | 2017-07-10 18:02:19 -0700 | [diff] [blame] | 47 | |
| 48 | #else /* CONFIG_SMP */ |
| 49 | |
| 50 | #include <asm/sbi.h> |
| 51 | |
Luc Van Oostenryck | 2861ae3 | 2018-06-01 17:21:21 +0200 | [diff] [blame] | 52 | #define flush_tlb_all() sbi_remote_sfence_vma(NULL, 0, -1) |
Palmer Dabbelt | fab957c | 2017-07-10 18:02:19 -0700 | [diff] [blame] | 53 | #define flush_tlb_page(vma, addr) flush_tlb_range(vma, addr, 0) |
| 54 | #define flush_tlb_range(vma, start, end) \ |
Andrew Waterman | f1b65f2 | 2017-10-26 01:53:40 -0700 | [diff] [blame] | 55 | sbi_remote_sfence_vma(mm_cpumask((vma)->vm_mm)->bits, \ |
| 56 | start, (end) - (start)) |
| 57 | #define flush_tlb_mm(mm) \ |
| 58 | sbi_remote_sfence_vma(mm_cpumask(mm)->bits, 0, -1) |
Palmer Dabbelt | fab957c | 2017-07-10 18:02:19 -0700 | [diff] [blame] | 59 | |
| 60 | #endif /* CONFIG_SMP */ |
| 61 | |
Palmer Dabbelt | fab957c | 2017-07-10 18:02:19 -0700 | [diff] [blame] | 62 | /* Flush a range of kernel pages */ |
| 63 | static inline void flush_tlb_kernel_range(unsigned long start, |
| 64 | unsigned long end) |
| 65 | { |
| 66 | flush_tlb_all(); |
| 67 | } |
| 68 | |
Palmer Dabbelt | fab957c | 2017-07-10 18:02:19 -0700 | [diff] [blame] | 69 | #endif /* _ASM_RISCV_TLBFLUSH_H */ |