blob: 0666a8d2959622208aaf36ad45f9777dfbdc1ed1 [file] [log] [blame]
Thomas Gleixner5b497af2019-05-29 07:18:09 -07001// SPDX-License-Identifier: GPL-2.0-only
Oliver O'Halloran32ce3862017-10-19 18:13:54 +11002/*
3 * Copyright(c) 2017 IBM Corporation. All rights reserved.
Oliver O'Halloran32ce3862017-10-19 18:13:54 +11004 */
5
6#include <linux/string.h>
7#include <linux/export.h>
Oliver O'Halloran6c447412017-10-19 18:13:55 +11008#include <linux/uaccess.h>
Oliver O'Halloran32ce3862017-10-19 18:13:54 +11009
10#include <asm/cacheflush.h>
11
12/*
13 * CONFIG_ARCH_HAS_PMEM_API symbols
14 */
15void arch_wb_cache_pmem(void *addr, size_t size)
16{
17 unsigned long start = (unsigned long) addr;
Christophe Leroy1cfb7252019-05-14 09:05:13 +000018 flush_dcache_range(start, start + size);
Oliver O'Halloran32ce3862017-10-19 18:13:54 +110019}
Aneesh Kumar K.V551003f2019-12-02 12:10:18 +053020EXPORT_SYMBOL_GPL(arch_wb_cache_pmem);
Oliver O'Halloran32ce3862017-10-19 18:13:54 +110021
22void arch_invalidate_pmem(void *addr, size_t size)
23{
24 unsigned long start = (unsigned long) addr;
Christophe Leroy1cfb7252019-05-14 09:05:13 +000025 flush_dcache_range(start, start + size);
Oliver O'Halloran32ce3862017-10-19 18:13:54 +110026}
Aneesh Kumar K.V551003f2019-12-02 12:10:18 +053027EXPORT_SYMBOL_GPL(arch_invalidate_pmem);
Oliver O'Halloran6c447412017-10-19 18:13:55 +110028
29/*
30 * CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE symbols
31 */
32long __copy_from_user_flushcache(void *dest, const void __user *src,
33 unsigned size)
34{
35 unsigned long copied, start = (unsigned long) dest;
36
37 copied = __copy_from_user(dest, src, size);
Christophe Leroy1cfb7252019-05-14 09:05:13 +000038 flush_dcache_range(start, start + size);
Oliver O'Halloran6c447412017-10-19 18:13:55 +110039
40 return copied;
41}
42
43void *memcpy_flushcache(void *dest, const void *src, size_t size)
44{
45 unsigned long start = (unsigned long) dest;
46
47 memcpy(dest, src, size);
Christophe Leroy1cfb7252019-05-14 09:05:13 +000048 flush_dcache_range(start, start + size);
Oliver O'Halloran6c447412017-10-19 18:13:55 +110049
50 return dest;
51}
52EXPORT_SYMBOL(memcpy_flushcache);
53
54void memcpy_page_flushcache(char *to, struct page *page, size_t offset,
55 size_t len)
56{
57 memcpy_flushcache(to, page_to_virt(page) + offset, len);
58}
59EXPORT_SYMBOL(memcpy_page_flushcache);