Merge branches 'x86/early-printk', 'x86/microcode' and 'core/objtool' into x86/urgent...
[sfrench/cifs-2.6.git] / arch / riscv / include / asm / tlbflush.h
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 #include <linux/mm_types.h>
19 #include <asm/smp.h>
20
21 /*
22  * Flush entire local TLB.  'sfence.vma' implicitly fences with the instruction
23  * cache as well, so a 'fence.i' is not necessary.
24  */
25 static inline void local_flush_tlb_all(void)
26 {
27         __asm__ __volatile__ ("sfence.vma" : : : "memory");
28 }
29
30 /* Flush one page from local TLB */
31 static inline void local_flush_tlb_page(unsigned long addr)
32 {
33         __asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory");
34 }
35
36 #ifndef CONFIG_SMP
37
38 #define flush_tlb_all() local_flush_tlb_all()
39 #define flush_tlb_page(vma, addr) local_flush_tlb_page(addr)
40
41 static inline void flush_tlb_range(struct vm_area_struct *vma,
42                 unsigned long start, unsigned long end)
43 {
44         local_flush_tlb_all();
45 }
46
47 #define flush_tlb_mm(mm) flush_tlb_all()
48
49 #else /* CONFIG_SMP */
50
51 #include <asm/sbi.h>
52
53 static inline void remote_sfence_vma(struct cpumask *cmask, unsigned long start,
54                                      unsigned long size)
55 {
56         struct cpumask hmask;
57
58         cpumask_clear(&hmask);
59         riscv_cpuid_to_hartid_mask(cmask, &hmask);
60         sbi_remote_sfence_vma(hmask.bits, start, size);
61 }
62
63 #define flush_tlb_all() sbi_remote_sfence_vma(NULL, 0, -1)
64 #define flush_tlb_page(vma, addr) flush_tlb_range(vma, addr, 0)
65 #define flush_tlb_range(vma, start, end) \
66         remote_sfence_vma(mm_cpumask((vma)->vm_mm), start, (end) - (start))
67 #define flush_tlb_mm(mm) \
68         remote_sfence_vma(mm_cpumask(mm), 0, -1)
69
70 #endif /* CONFIG_SMP */
71
72 /* Flush a range of kernel pages */
73 static inline void flush_tlb_kernel_range(unsigned long start,
74         unsigned long end)
75 {
76         flush_tlb_all();
77 }
78
79 #endif /* _ASM_RISCV_TLBFLUSH_H */