18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2017 ARM Ltd.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/uaccess.h>
78c2ecf20Sopenharmony_ci#include <asm/barrier.h>
88c2ecf20Sopenharmony_ci#include <asm/cacheflush.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_civoid memcpy_flushcache(void *dst, const void *src, size_t cnt)
118c2ecf20Sopenharmony_ci{
128c2ecf20Sopenharmony_ci	/*
138c2ecf20Sopenharmony_ci	 * We assume this should not be called with @dst pointing to
148c2ecf20Sopenharmony_ci	 * non-cacheable memory, such that we don't need an explicit
158c2ecf20Sopenharmony_ci	 * barrier to order the cache maintenance against the memcpy.
168c2ecf20Sopenharmony_ci	 */
178c2ecf20Sopenharmony_ci	memcpy(dst, src, cnt);
188c2ecf20Sopenharmony_ci	__clean_dcache_area_pop(dst, cnt);
198c2ecf20Sopenharmony_ci}
208c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(memcpy_flushcache);
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_civoid memcpy_page_flushcache(char *to, struct page *page, size_t offset,
238c2ecf20Sopenharmony_ci			    size_t len)
248c2ecf20Sopenharmony_ci{
258c2ecf20Sopenharmony_ci	memcpy_flushcache(to, page_address(page) + offset, len);
268c2ecf20Sopenharmony_ci}
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ciunsigned long __copy_user_flushcache(void *to, const void __user *from,
298c2ecf20Sopenharmony_ci				     unsigned long n)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	unsigned long rc;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	uaccess_enable_not_uao();
348c2ecf20Sopenharmony_ci	rc = __arch_copy_from_user(to, from, n);
358c2ecf20Sopenharmony_ci	uaccess_disable_not_uao();
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	/* See above */
388c2ecf20Sopenharmony_ci	__clean_dcache_area_pop(to, n - rc);
398c2ecf20Sopenharmony_ci	return rc;
408c2ecf20Sopenharmony_ci}
41