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 | |
| 18 | #ifdef CONFIG_MMU |
| 19 | |
Andrew Waterman | 08f051e | 2017-10-25 14:30:32 -0700 | [diff] [blame^] | 20 | #include <linux/mm_types.h> |
| 21 | |
Palmer Dabbelt | fab957c | 2017-07-10 18:02:19 -0700 | [diff] [blame] | 22 | /* Flush entire local TLB */ |
| 23 | static inline void local_flush_tlb_all(void) |
| 24 | { |
| 25 | __asm__ __volatile__ ("sfence.vma" : : : "memory"); |
| 26 | } |
| 27 | |
| 28 | /* Flush one page from local TLB */ |
| 29 | static inline void local_flush_tlb_page(unsigned long addr) |
| 30 | { |
| 31 | __asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory"); |
| 32 | } |
| 33 | |
| 34 | #ifndef CONFIG_SMP |
| 35 | |
| 36 | #define flush_tlb_all() local_flush_tlb_all() |
| 37 | #define flush_tlb_page(vma, addr) local_flush_tlb_page(addr) |
| 38 | #define flush_tlb_range(vma, start, end) local_flush_tlb_all() |
| 39 | |
| 40 | #else /* CONFIG_SMP */ |
| 41 | |
| 42 | #include <asm/sbi.h> |
| 43 | |
| 44 | #define flush_tlb_all() sbi_remote_sfence_vma(0, 0, -1) |
| 45 | #define flush_tlb_page(vma, addr) flush_tlb_range(vma, addr, 0) |
| 46 | #define flush_tlb_range(vma, start, end) \ |
| 47 | sbi_remote_sfence_vma(0, start, (end) - (start)) |
| 48 | |
| 49 | #endif /* CONFIG_SMP */ |
| 50 | |
| 51 | /* Flush the TLB entries of the specified mm context */ |
| 52 | static inline void flush_tlb_mm(struct mm_struct *mm) |
| 53 | { |
| 54 | flush_tlb_all(); |
| 55 | } |
| 56 | |
| 57 | /* Flush a range of kernel pages */ |
| 58 | static inline void flush_tlb_kernel_range(unsigned long start, |
| 59 | unsigned long end) |
| 60 | { |
| 61 | flush_tlb_all(); |
| 62 | } |
| 63 | |
| 64 | #endif /* CONFIG_MMU */ |
| 65 | |
| 66 | #endif /* _ASM_RISCV_TLBFLUSH_H */ |