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