1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2017 ARM Ltd.
4  */
5 
6 #include <linux/uaccess.h>
7 #include <asm/barrier.h>
8 #include <asm/cacheflush.h>
9 
memcpy_flushcache(void * dst,const void * src,size_t cnt)10 void memcpy_flushcache(void *dst, const void *src, size_t cnt)
11 {
12 	/*
13 	 * We assume this should not be called with @dst pointing to
14 	 * non-cacheable memory, such that we don't need an explicit
15 	 * barrier to order the cache maintenance against the memcpy.
16 	 */
17 	memcpy(dst, src, cnt);
18 	dcache_clean_pop((unsigned long)dst, (unsigned long)dst + cnt);
19 }
20 EXPORT_SYMBOL_GPL(memcpy_flushcache);
21 
memcpy_page_flushcache(char * to,struct page * page,size_t offset,size_t len)22 void memcpy_page_flushcache(char *to, struct page *page, size_t offset,
23 			    size_t len)
24 {
25 	memcpy_flushcache(to, page_address(page) + offset, len);
26 }
27 
__copy_user_flushcache(void * to,const void __user * from,unsigned long n)28 unsigned long __copy_user_flushcache(void *to, const void __user *from,
29 				     unsigned long n)
30 {
31 	unsigned long rc;
32 
33 	rc = raw_copy_from_user(to, from, n);
34 
35 	/* See above */
36 	dcache_clean_pop((unsigned long)to, (unsigned long)to + n - rc);
37 	return rc;
38 }
39