blob: efd89a88d2d0e9b2bcd639a436a6143440a24d77 [file] [log] [blame]
Palmer Dabbeltfab957c2017-07-10 18:02:19 -07001/*
2 * Copyright (C) 2015 Regents of the University of California
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#ifndef _ASM_RISCV_CACHEFLUSH_H
15#define _ASM_RISCV_CACHEFLUSH_H
16
17#include <asm-generic/cacheflush.h>
18
19#undef flush_icache_range
20#undef flush_icache_user_range
Andrew Waterman08f051e2017-10-25 14:30:32 -070021#undef flush_dcache_page
Palmer Dabbeltfab957c2017-07-10 18:02:19 -070022
23static inline void local_flush_icache_all(void)
24{
25 asm volatile ("fence.i" ::: "memory");
26}
27
Andrew Waterman08f051e2017-10-25 14:30:32 -070028#define PG_dcache_clean PG_arch_1
29
30static inline void flush_dcache_page(struct page *page)
31{
32 if (test_bit(PG_dcache_clean, &page->flags))
33 clear_bit(PG_dcache_clean, &page->flags);
34}
35
36/*
37 * RISC-V doesn't have an instruction to flush parts of the instruction cache,
38 * so instead we just flush the whole thing.
39 */
40#define flush_icache_range(start, end) flush_icache_all()
41#define flush_icache_user_range(vma, pg, addr, len) flush_icache_all()
42
Palmer Dabbeltfab957c2017-07-10 18:02:19 -070043#ifndef CONFIG_SMP
44
Andrew Waterman08f051e2017-10-25 14:30:32 -070045#define flush_icache_all() local_flush_icache_all()
46#define flush_icache_mm(mm, local) flush_icache_all()
Palmer Dabbeltfab957c2017-07-10 18:02:19 -070047
48#else /* CONFIG_SMP */
49
Andrew Waterman08f051e2017-10-25 14:30:32 -070050#define flush_icache_all() sbi_remote_fence_i(0)
51void flush_icache_mm(struct mm_struct *mm, bool local);
Palmer Dabbeltfab957c2017-07-10 18:02:19 -070052
53#endif /* CONFIG_SMP */
54
Andrew Waterman921ebd82017-10-25 14:32:16 -070055/*
56 * Bits in sys_riscv_flush_icache()'s flags argument.
57 */
58#define SYS_RISCV_FLUSH_ICACHE_LOCAL 1UL
59#define SYS_RISCV_FLUSH_ICACHE_ALL (SYS_RISCV_FLUSH_ICACHE_LOCAL)
60
Palmer Dabbeltfab957c2017-07-10 18:02:19 -070061#endif /* _ASM_RISCV_CACHEFLUSH_H */