blob: ad8678f1b54a3bf0010987891ac9ee2b4e8f2d5b [file] [log] [blame]
Thomas Gleixner50acfb22019-05-29 07:18:00 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Palmer Dabbeltfab957c2017-07-10 18:02:19 -07002/*
3 * Copyright (C) 2015 Regents of the University of California
Palmer Dabbeltfab957c2017-07-10 18:02:19 -07004 */
5
6#ifndef _ASM_RISCV_CACHEFLUSH_H
7#define _ASM_RISCV_CACHEFLUSH_H
8
9#include <asm-generic/cacheflush.h>
10
11#undef flush_icache_range
12#undef flush_icache_user_range
Andrew Waterman08f051e2017-10-25 14:30:32 -070013#undef flush_dcache_page
Palmer Dabbeltfab957c2017-07-10 18:02:19 -070014
15static inline void local_flush_icache_all(void)
16{
17 asm volatile ("fence.i" ::: "memory");
18}
19
Andrew Waterman08f051e2017-10-25 14:30:32 -070020#define PG_dcache_clean PG_arch_1
21
22static inline void flush_dcache_page(struct page *page)
23{
24 if (test_bit(PG_dcache_clean, &page->flags))
25 clear_bit(PG_dcache_clean, &page->flags);
26}
27
28/*
29 * RISC-V doesn't have an instruction to flush parts of the instruction cache,
30 * so instead we just flush the whole thing.
31 */
32#define flush_icache_range(start, end) flush_icache_all()
33#define flush_icache_user_range(vma, pg, addr, len) flush_icache_all()
34
Palmer Dabbeltfab957c2017-07-10 18:02:19 -070035#ifndef CONFIG_SMP
36
Andrew Waterman08f051e2017-10-25 14:30:32 -070037#define flush_icache_all() local_flush_icache_all()
38#define flush_icache_mm(mm, local) flush_icache_all()
Palmer Dabbeltfab957c2017-07-10 18:02:19 -070039
40#else /* CONFIG_SMP */
41
Gary Guo58de7752019-03-27 00:41:25 +000042void flush_icache_all(void);
Andrew Waterman08f051e2017-10-25 14:30:32 -070043void flush_icache_mm(struct mm_struct *mm, bool local);
Palmer Dabbeltfab957c2017-07-10 18:02:19 -070044
45#endif /* CONFIG_SMP */
46
Andrew Waterman921ebd82017-10-25 14:32:16 -070047/*
48 * Bits in sys_riscv_flush_icache()'s flags argument.
49 */
50#define SYS_RISCV_FLUSH_ICACHE_LOCAL 1UL
51#define SYS_RISCV_FLUSH_ICACHE_ALL (SYS_RISCV_FLUSH_ICACHE_LOCAL)
52
Palmer Dabbeltfab957c2017-07-10 18:02:19 -070053#endif /* _ASM_RISCV_CACHEFLUSH_H */