162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __ASM_SH_CACHEFLUSH_H
362306a36Sopenharmony_ci#define __ASM_SH_CACHEFLUSH_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/mm.h>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci/*
862306a36Sopenharmony_ci * Cache flushing:
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci *  - flush_cache_all() flushes entire cache
1162306a36Sopenharmony_ci *  - flush_cache_mm(mm) flushes the specified mm context's cache lines
1262306a36Sopenharmony_ci *  - flush_cache_dup mm(mm) handles cache flushing when forking
1362306a36Sopenharmony_ci *  - flush_cache_page(mm, vmaddr, pfn) flushes a single page
1462306a36Sopenharmony_ci *  - flush_cache_range(vma, start, end) flushes a range of pages
1562306a36Sopenharmony_ci *
1662306a36Sopenharmony_ci *  - flush_dcache_folio(folio) flushes(wback&invalidates) a folio for dcache
1762306a36Sopenharmony_ci *  - flush_icache_range(start, end) flushes(invalidates) a range for icache
1862306a36Sopenharmony_ci *  - flush_icache_pages(vma, pg, nr) flushes(invalidates) pages for icache
1962306a36Sopenharmony_ci *  - flush_cache_sigtramp(vaddr) flushes the signal trampoline
2062306a36Sopenharmony_ci */
2162306a36Sopenharmony_ciextern void (*local_flush_cache_all)(void *args);
2262306a36Sopenharmony_ciextern void (*local_flush_cache_mm)(void *args);
2362306a36Sopenharmony_ciextern void (*local_flush_cache_dup_mm)(void *args);
2462306a36Sopenharmony_ciextern void (*local_flush_cache_page)(void *args);
2562306a36Sopenharmony_ciextern void (*local_flush_cache_range)(void *args);
2662306a36Sopenharmony_ciextern void (*local_flush_dcache_folio)(void *args);
2762306a36Sopenharmony_ciextern void (*local_flush_icache_range)(void *args);
2862306a36Sopenharmony_ciextern void (*local_flush_icache_folio)(void *args);
2962306a36Sopenharmony_ciextern void (*local_flush_cache_sigtramp)(void *args);
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_cistatic inline void cache_noop(void *args) { }
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ciextern void (*__flush_wback_region)(void *start, int size);
3462306a36Sopenharmony_ciextern void (*__flush_purge_region)(void *start, int size);
3562306a36Sopenharmony_ciextern void (*__flush_invalidate_region)(void *start, int size);
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ciextern void flush_cache_all(void);
3862306a36Sopenharmony_ciextern void flush_cache_mm(struct mm_struct *mm);
3962306a36Sopenharmony_ciextern void flush_cache_dup_mm(struct mm_struct *mm);
4062306a36Sopenharmony_ciextern void flush_cache_page(struct vm_area_struct *vma,
4162306a36Sopenharmony_ci				unsigned long addr, unsigned long pfn);
4262306a36Sopenharmony_ciextern void flush_cache_range(struct vm_area_struct *vma,
4362306a36Sopenharmony_ci				 unsigned long start, unsigned long end);
4462306a36Sopenharmony_ci#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
4562306a36Sopenharmony_civoid flush_dcache_folio(struct folio *folio);
4662306a36Sopenharmony_ci#define flush_dcache_folio flush_dcache_folio
4762306a36Sopenharmony_cistatic inline void flush_dcache_page(struct page *page)
4862306a36Sopenharmony_ci{
4962306a36Sopenharmony_ci	flush_dcache_folio(page_folio(page));
5062306a36Sopenharmony_ci}
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ciextern void flush_icache_range(unsigned long start, unsigned long end);
5362306a36Sopenharmony_ci#define flush_icache_user_range flush_icache_range
5462306a36Sopenharmony_civoid flush_icache_pages(struct vm_area_struct *vma, struct page *page,
5562306a36Sopenharmony_ci		unsigned int nr);
5662306a36Sopenharmony_ci#define flush_icache_pages flush_icache_pages
5762306a36Sopenharmony_ciextern void flush_cache_sigtramp(unsigned long address);
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_cistruct flusher_data {
6062306a36Sopenharmony_ci	struct vm_area_struct *vma;
6162306a36Sopenharmony_ci	unsigned long addr1, addr2;
6262306a36Sopenharmony_ci};
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci#define ARCH_HAS_FLUSH_ANON_PAGE
6562306a36Sopenharmony_ciextern void __flush_anon_page(struct page *page, unsigned long);
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_cistatic inline void flush_anon_page(struct vm_area_struct *vma,
6862306a36Sopenharmony_ci				   struct page *page, unsigned long vmaddr)
6962306a36Sopenharmony_ci{
7062306a36Sopenharmony_ci	if (boot_cpu_data.dcache.n_aliases && PageAnon(page))
7162306a36Sopenharmony_ci		__flush_anon_page(page, vmaddr);
7262306a36Sopenharmony_ci}
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define ARCH_IMPLEMENTS_FLUSH_KERNEL_VMAP_RANGE 1
7562306a36Sopenharmony_cistatic inline void flush_kernel_vmap_range(void *addr, int size)
7662306a36Sopenharmony_ci{
7762306a36Sopenharmony_ci	__flush_wback_region(addr, size);
7862306a36Sopenharmony_ci}
7962306a36Sopenharmony_cistatic inline void invalidate_kernel_vmap_range(void *addr, int size)
8062306a36Sopenharmony_ci{
8162306a36Sopenharmony_ci	__flush_invalidate_region(addr, size);
8262306a36Sopenharmony_ci}
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ciextern void copy_to_user_page(struct vm_area_struct *vma,
8562306a36Sopenharmony_ci	struct page *page, unsigned long vaddr, void *dst, const void *src,
8662306a36Sopenharmony_ci	unsigned long len);
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ciextern void copy_from_user_page(struct vm_area_struct *vma,
8962306a36Sopenharmony_ci	struct page *page, unsigned long vaddr, void *dst, const void *src,
9062306a36Sopenharmony_ci	unsigned long len);
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci#define flush_cache_vmap(start, end)		local_flush_cache_all(NULL)
9362306a36Sopenharmony_ci#define flush_cache_vmap_early(start, end)	do { } while (0)
9462306a36Sopenharmony_ci#define flush_cache_vunmap(start, end)		local_flush_cache_all(NULL)
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci#define flush_dcache_mmap_lock(mapping)		do { } while (0)
9762306a36Sopenharmony_ci#define flush_dcache_mmap_unlock(mapping)	do { } while (0)
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_civoid kmap_coherent_init(void);
10062306a36Sopenharmony_civoid *kmap_coherent(struct page *page, unsigned long addr);
10162306a36Sopenharmony_civoid kunmap_coherent(void *kvaddr);
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci#define PG_dcache_clean	PG_arch_1
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_civoid cpu_cache_init(void);
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_cistatic inline void *sh_cacheop_vaddr(void *vaddr)
10862306a36Sopenharmony_ci{
10962306a36Sopenharmony_ci	if (__in_29bit_mode())
11062306a36Sopenharmony_ci		vaddr = (void *)CAC_ADDR((unsigned long)vaddr);
11162306a36Sopenharmony_ci	return vaddr;
11262306a36Sopenharmony_ci}
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci#endif /* __ASM_SH_CACHEFLUSH_H */
115