18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
38c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
48c2ecf20Sopenharmony_ci * for more details.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 01, 02, 03 by Ralf Baechle
78c2ecf20Sopenharmony_ci * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#ifndef _ASM_CACHEFLUSH_H
108c2ecf20Sopenharmony_ci#define _ASM_CACHEFLUSH_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/* Keep includes the same across arches.  */
138c2ecf20Sopenharmony_ci#include <linux/mm.h>
148c2ecf20Sopenharmony_ci#include <asm/cpu-features.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/* Cache flushing:
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci *  - flush_cache_all() flushes entire cache
198c2ecf20Sopenharmony_ci *  - flush_cache_mm(mm) flushes the specified mm context's cache lines
208c2ecf20Sopenharmony_ci *  - flush_cache_dup mm(mm) handles cache flushing when forking
218c2ecf20Sopenharmony_ci *  - flush_cache_page(mm, vmaddr, pfn) flushes a single page
228c2ecf20Sopenharmony_ci *  - flush_cache_range(vma, start, end) flushes a range of pages
238c2ecf20Sopenharmony_ci *  - flush_icache_range(start, end) flush a range of instructions
248c2ecf20Sopenharmony_ci *  - flush_dcache_page(pg) flushes(wback&invalidates) a page for dcache
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci * MIPS specific flush operations:
278c2ecf20Sopenharmony_ci *
288c2ecf20Sopenharmony_ci *  - flush_icache_all() flush the entire instruction cache
298c2ecf20Sopenharmony_ci *  - flush_data_cache_page() flushes a page from the data cache
308c2ecf20Sopenharmony_ci *  - __flush_icache_user_range(start, end) flushes range of user instructions
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci /*
348c2ecf20Sopenharmony_ci * This flag is used to indicate that the page pointed to by a pte
358c2ecf20Sopenharmony_ci * is dirty and requires cleaning before returning it to the user.
368c2ecf20Sopenharmony_ci */
378c2ecf20Sopenharmony_ci#define PG_dcache_dirty			PG_arch_1
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define Page_dcache_dirty(page)		\
408c2ecf20Sopenharmony_ci	test_bit(PG_dcache_dirty, &(page)->flags)
418c2ecf20Sopenharmony_ci#define SetPageDcacheDirty(page)	\
428c2ecf20Sopenharmony_ci	set_bit(PG_dcache_dirty, &(page)->flags)
438c2ecf20Sopenharmony_ci#define ClearPageDcacheDirty(page)	\
448c2ecf20Sopenharmony_ci	clear_bit(PG_dcache_dirty, &(page)->flags)
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ciextern void (*flush_cache_all)(void);
478c2ecf20Sopenharmony_ciextern void (*__flush_cache_all)(void);
488c2ecf20Sopenharmony_ciextern void (*flush_cache_mm)(struct mm_struct *mm);
498c2ecf20Sopenharmony_ci#define flush_cache_dup_mm(mm)	do { (void) (mm); } while (0)
508c2ecf20Sopenharmony_ciextern void (*flush_cache_range)(struct vm_area_struct *vma,
518c2ecf20Sopenharmony_ci	unsigned long start, unsigned long end);
528c2ecf20Sopenharmony_ciextern void (*flush_cache_page)(struct vm_area_struct *vma, unsigned long page, unsigned long pfn);
538c2ecf20Sopenharmony_ciextern void __flush_dcache_page(struct page *page);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
568c2ecf20Sopenharmony_cistatic inline void flush_dcache_page(struct page *page)
578c2ecf20Sopenharmony_ci{
588c2ecf20Sopenharmony_ci	if (cpu_has_dc_aliases)
598c2ecf20Sopenharmony_ci		__flush_dcache_page(page);
608c2ecf20Sopenharmony_ci	else if (!cpu_has_ic_fills_f_dc)
618c2ecf20Sopenharmony_ci		SetPageDcacheDirty(page);
628c2ecf20Sopenharmony_ci}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#define flush_dcache_mmap_lock(mapping)		do { } while (0)
658c2ecf20Sopenharmony_ci#define flush_dcache_mmap_unlock(mapping)	do { } while (0)
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#define ARCH_HAS_FLUSH_ANON_PAGE
688c2ecf20Sopenharmony_ciextern void __flush_anon_page(struct page *, unsigned long);
698c2ecf20Sopenharmony_cistatic inline void flush_anon_page(struct vm_area_struct *vma,
708c2ecf20Sopenharmony_ci	struct page *page, unsigned long vmaddr)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	if (cpu_has_dc_aliases && PageAnon(page))
738c2ecf20Sopenharmony_ci		__flush_anon_page(page, vmaddr);
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistatic inline void flush_icache_page(struct vm_area_struct *vma,
778c2ecf20Sopenharmony_ci	struct page *page)
788c2ecf20Sopenharmony_ci{
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ciextern void (*flush_icache_range)(unsigned long start, unsigned long end);
828c2ecf20Sopenharmony_ciextern void (*local_flush_icache_range)(unsigned long start, unsigned long end);
838c2ecf20Sopenharmony_ciextern void (*__flush_icache_user_range)(unsigned long start,
848c2ecf20Sopenharmony_ci					 unsigned long end);
858c2ecf20Sopenharmony_ciextern void (*__local_flush_icache_user_range)(unsigned long start,
868c2ecf20Sopenharmony_ci					       unsigned long end);
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ciextern void (*__flush_cache_vmap)(void);
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistatic inline void flush_cache_vmap(unsigned long start, unsigned long end)
918c2ecf20Sopenharmony_ci{
928c2ecf20Sopenharmony_ci	if (cpu_has_dc_aliases)
938c2ecf20Sopenharmony_ci		__flush_cache_vmap();
948c2ecf20Sopenharmony_ci}
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ciextern void (*__flush_cache_vunmap)(void);
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistatic inline void flush_cache_vunmap(unsigned long start, unsigned long end)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	if (cpu_has_dc_aliases)
1018c2ecf20Sopenharmony_ci		__flush_cache_vunmap();
1028c2ecf20Sopenharmony_ci}
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ciextern void copy_to_user_page(struct vm_area_struct *vma,
1058c2ecf20Sopenharmony_ci	struct page *page, unsigned long vaddr, void *dst, const void *src,
1068c2ecf20Sopenharmony_ci	unsigned long len);
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ciextern void copy_from_user_page(struct vm_area_struct *vma,
1098c2ecf20Sopenharmony_ci	struct page *page, unsigned long vaddr, void *dst, const void *src,
1108c2ecf20Sopenharmony_ci	unsigned long len);
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ciextern void (*flush_icache_all)(void);
1138c2ecf20Sopenharmony_ciextern void (*local_flush_data_cache_page)(void * addr);
1148c2ecf20Sopenharmony_ciextern void (*flush_data_cache_page)(unsigned long addr);
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/* Run kernel code uncached, useful for cache probing functions. */
1178c2ecf20Sopenharmony_ciunsigned long run_uncached(void *func);
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ciextern void *kmap_coherent(struct page *page, unsigned long addr);
1208c2ecf20Sopenharmony_ciextern void kunmap_coherent(void);
1218c2ecf20Sopenharmony_ciextern void *kmap_noncoherent(struct page *page, unsigned long addr);
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_cistatic inline void kunmap_noncoherent(void)
1248c2ecf20Sopenharmony_ci{
1258c2ecf20Sopenharmony_ci	kunmap_coherent();
1268c2ecf20Sopenharmony_ci}
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#define ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
1298c2ecf20Sopenharmony_cistatic inline void flush_kernel_dcache_page(struct page *page)
1308c2ecf20Sopenharmony_ci{
1318c2ecf20Sopenharmony_ci	BUG_ON(cpu_has_dc_aliases && PageHighMem(page));
1328c2ecf20Sopenharmony_ci	flush_dcache_page(page);
1338c2ecf20Sopenharmony_ci}
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci/*
1368c2ecf20Sopenharmony_ci * For now flush_kernel_vmap_range and invalidate_kernel_vmap_range both do a
1378c2ecf20Sopenharmony_ci * cache writeback and invalidate operation.
1388c2ecf20Sopenharmony_ci */
1398c2ecf20Sopenharmony_ciextern void (*__flush_kernel_vmap_range)(unsigned long vaddr, int size);
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_cistatic inline void flush_kernel_vmap_range(void *vaddr, int size)
1428c2ecf20Sopenharmony_ci{
1438c2ecf20Sopenharmony_ci	if (cpu_has_dc_aliases)
1448c2ecf20Sopenharmony_ci		__flush_kernel_vmap_range((unsigned long) vaddr, size);
1458c2ecf20Sopenharmony_ci}
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_cistatic inline void invalidate_kernel_vmap_range(void *vaddr, int size)
1488c2ecf20Sopenharmony_ci{
1498c2ecf20Sopenharmony_ci	if (cpu_has_dc_aliases)
1508c2ecf20Sopenharmony_ci		__flush_kernel_vmap_range((unsigned long) vaddr, size);
1518c2ecf20Sopenharmony_ci}
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci#endif /* _ASM_CACHEFLUSH_H */
154