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