1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2015 Regents of the University of California
6 #ifndef _ASM_RISCV_CACHEFLUSH_H
7 #define _ASM_RISCV_CACHEFLUSH_H
11 #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
14 * The cache doesn't need to be flushed when TLB entries change when
15 * the cache is mapped to physical memory, not virtual memory
17 static inline void flush_cache_all(void)
21 static inline void flush_cache_mm(struct mm_struct
*mm
)
25 static inline void flush_cache_dup_mm(struct mm_struct
*mm
)
29 static inline void flush_cache_range(struct vm_area_struct
*vma
,
35 static inline void flush_cache_page(struct vm_area_struct
*vma
,
41 static inline void flush_dcache_mmap_lock(struct address_space
*mapping
)
45 static inline void flush_dcache_mmap_unlock(struct address_space
*mapping
)
49 static inline void flush_icache_page(struct vm_area_struct
*vma
,
54 static inline void flush_cache_vmap(unsigned long start
, unsigned long end
)
58 static inline void flush_cache_vunmap(unsigned long start
, unsigned long end
)
62 #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
64 memcpy(dst, src, len); \
65 flush_icache_user_range(vma, page, vaddr, len); \
67 #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
70 static inline void local_flush_icache_all(void)
72 asm volatile ("fence.i" ::: "memory");
75 #define PG_dcache_clean PG_arch_1
77 static inline void flush_dcache_page(struct page
*page
)
79 if (test_bit(PG_dcache_clean
, &page
->flags
))
80 clear_bit(PG_dcache_clean
, &page
->flags
);
84 * RISC-V doesn't have an instruction to flush parts of the instruction cache,
85 * so instead we just flush the whole thing.
87 #define flush_icache_range(start, end) flush_icache_all()
88 #define flush_icache_user_range(vma, pg, addr, len) flush_icache_all()
92 #define flush_icache_all() local_flush_icache_all()
93 #define flush_icache_mm(mm, local) flush_icache_all()
95 #else /* CONFIG_SMP */
97 void flush_icache_all(void);
98 void flush_icache_mm(struct mm_struct
*mm
, bool local
);
100 #endif /* CONFIG_SMP */
103 * Bits in sys_riscv_flush_icache()'s flags argument.
105 #define SYS_RISCV_FLUSH_ICACHE_LOCAL 1UL
106 #define SYS_RISCV_FLUSH_ICACHE_ALL (SYS_RISCV_FLUSH_ICACHE_LOCAL)
108 #endif /* _ASM_RISCV_CACHEFLUSH_H */