162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci#ifndef __ABI_CSKY_CACHEFLUSH_H
462306a36Sopenharmony_ci#define __ABI_CSKY_CACHEFLUSH_H
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#include <linux/mm.h>
762306a36Sopenharmony_ci#include <asm/string.h>
862306a36Sopenharmony_ci#include <asm/cache.h>
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
1162306a36Sopenharmony_ciextern void flush_dcache_page(struct page *);
1262306a36Sopenharmony_civoid flush_dcache_folio(struct folio *);
1362306a36Sopenharmony_ci#define flush_dcache_folio flush_dcache_folio
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#define flush_cache_mm(mm)			dcache_wbinv_all()
1662306a36Sopenharmony_ci#define flush_cache_page(vma, page, pfn)	cache_wbinv_all()
1762306a36Sopenharmony_ci#define flush_cache_dup_mm(mm)			cache_wbinv_all()
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#define flush_dcache_mmap_lock(mapping)		xa_lock_irq(&mapping->i_pages)
2062306a36Sopenharmony_ci#define flush_dcache_mmap_unlock(mapping)	xa_unlock_irq(&mapping->i_pages)
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#define ARCH_IMPLEMENTS_FLUSH_KERNEL_VMAP_RANGE 1
2362306a36Sopenharmony_cistatic inline void flush_kernel_vmap_range(void *addr, int size)
2462306a36Sopenharmony_ci{
2562306a36Sopenharmony_ci	dcache_wbinv_all();
2662306a36Sopenharmony_ci}
2762306a36Sopenharmony_cistatic inline void invalidate_kernel_vmap_range(void *addr, int size)
2862306a36Sopenharmony_ci{
2962306a36Sopenharmony_ci	dcache_wbinv_all();
3062306a36Sopenharmony_ci}
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define ARCH_HAS_FLUSH_ANON_PAGE
3362306a36Sopenharmony_cistatic inline void flush_anon_page(struct vm_area_struct *vma,
3462306a36Sopenharmony_ci			 struct page *page, unsigned long vmaddr)
3562306a36Sopenharmony_ci{
3662306a36Sopenharmony_ci	if (PageAnon(page))
3762306a36Sopenharmony_ci		cache_wbinv_all();
3862306a36Sopenharmony_ci}
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci/*
4162306a36Sopenharmony_ci * if (current_mm != vma->mm) cache_wbinv_range(start, end) will be broken.
4262306a36Sopenharmony_ci * Use cache_wbinv_all() here and need to be improved in future.
4362306a36Sopenharmony_ci */
4462306a36Sopenharmony_ciextern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
4562306a36Sopenharmony_ci#define flush_cache_vmap(start, end)		cache_wbinv_all()
4662306a36Sopenharmony_ci#define flush_cache_vmap_early(start, end)	do { } while (0)
4762306a36Sopenharmony_ci#define flush_cache_vunmap(start, end)		cache_wbinv_all()
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define flush_icache_range(start, end)		cache_wbinv_range(start, end)
5062306a36Sopenharmony_ci#define flush_icache_mm_range(mm, start, end)	cache_wbinv_range(start, end)
5162306a36Sopenharmony_ci#define flush_icache_deferred(mm)		do {} while (0);
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
5462306a36Sopenharmony_cido { \
5562306a36Sopenharmony_ci	memcpy(dst, src, len); \
5662306a36Sopenharmony_ci} while (0)
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
5962306a36Sopenharmony_cido { \
6062306a36Sopenharmony_ci	memcpy(dst, src, len); \
6162306a36Sopenharmony_ci	cache_wbinv_all(); \
6262306a36Sopenharmony_ci} while (0)
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci#endif /* __ABI_CSKY_CACHEFLUSH_H */
65