1caab277bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
221cfa0e9SRobin Murphy /*
321cfa0e9SRobin Murphy  * Copyright (C) 2017 ARM Ltd.
421cfa0e9SRobin Murphy  */
521cfa0e9SRobin Murphy 
621cfa0e9SRobin Murphy #include <linux/uaccess.h>
721cfa0e9SRobin Murphy #include <asm/barrier.h>
821cfa0e9SRobin Murphy #include <asm/cacheflush.h>
921cfa0e9SRobin Murphy 
memcpy_flushcache(void * dst,const void * src,size_t cnt)1021cfa0e9SRobin Murphy void memcpy_flushcache(void *dst, const void *src, size_t cnt)
1121cfa0e9SRobin Murphy {
1221cfa0e9SRobin Murphy 	/*
1321cfa0e9SRobin Murphy 	 * We assume this should not be called with @dst pointing to
1421cfa0e9SRobin Murphy 	 * non-cacheable memory, such that we don't need an explicit
1521cfa0e9SRobin Murphy 	 * barrier to order the cache maintenance against the memcpy.
1621cfa0e9SRobin Murphy 	 */
1721cfa0e9SRobin Murphy 	memcpy(dst, src, cnt);
18*fade9c2cSFuad Tabba 	dcache_clean_pop((unsigned long)dst, (unsigned long)dst + cnt);
1921cfa0e9SRobin Murphy }
2021cfa0e9SRobin Murphy EXPORT_SYMBOL_GPL(memcpy_flushcache);
2121cfa0e9SRobin Murphy 
__copy_user_flushcache(void * to,const void __user * from,unsigned long n)2221cfa0e9SRobin Murphy unsigned long __copy_user_flushcache(void *to, const void __user *from,
2321cfa0e9SRobin Murphy 				     unsigned long n)
2421cfa0e9SRobin Murphy {
25e50be648SPavel Tatashin 	unsigned long rc;
26e50be648SPavel Tatashin 
279e94fdadSMark Rutland 	rc = raw_copy_from_user(to, from, n);
2821cfa0e9SRobin Murphy 
2921cfa0e9SRobin Murphy 	/* See above */
30*fade9c2cSFuad Tabba 	dcache_clean_pop((unsigned long)to, (unsigned long)to + n - rc);
3121cfa0e9SRobin Murphy 	return rc;
3221cfa0e9SRobin Murphy }
33