162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2017 ARM Ltd.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#include <linux/uaccess.h>
762306a36Sopenharmony_ci#include <asm/barrier.h>
862306a36Sopenharmony_ci#include <asm/cacheflush.h>
962306a36Sopenharmony_ci
1062306a36Sopenharmony_civoid memcpy_flushcache(void *dst, const void *src, size_t cnt)
1162306a36Sopenharmony_ci{
1262306a36Sopenharmony_ci	/*
1362306a36Sopenharmony_ci	 * We assume this should not be called with @dst pointing to
1462306a36Sopenharmony_ci	 * non-cacheable memory, such that we don't need an explicit
1562306a36Sopenharmony_ci	 * barrier to order the cache maintenance against the memcpy.
1662306a36Sopenharmony_ci	 */
1762306a36Sopenharmony_ci	memcpy(dst, src, cnt);
1862306a36Sopenharmony_ci	dcache_clean_pop((unsigned long)dst, (unsigned long)dst + cnt);
1962306a36Sopenharmony_ci}
2062306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(memcpy_flushcache);
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ciunsigned long __copy_user_flushcache(void *to, const void __user *from,
2362306a36Sopenharmony_ci				     unsigned long n)
2462306a36Sopenharmony_ci{
2562306a36Sopenharmony_ci	unsigned long rc;
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci	rc = raw_copy_from_user(to, from, n);
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci	/* See above */
3062306a36Sopenharmony_ci	dcache_clean_pop((unsigned long)to, (unsigned long)to + n - rc);
3162306a36Sopenharmony_ci	return rc;
3262306a36Sopenharmony_ci}
33