xref: /openbmc/linux/arch/powerpc/lib/pmem.c (revision 7b73a9c8)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright(c) 2017 IBM Corporation. All rights reserved.
4  */
5 
6 #include <linux/string.h>
7 #include <linux/export.h>
8 #include <linux/uaccess.h>
9 
10 #include <asm/cacheflush.h>
11 
12 /*
13  * CONFIG_ARCH_HAS_PMEM_API symbols
14  */
15 void arch_wb_cache_pmem(void *addr, size_t size)
16 {
17 	unsigned long start = (unsigned long) addr;
18 	flush_dcache_range(start, start + size);
19 }
20 EXPORT_SYMBOL_GPL(arch_wb_cache_pmem);
21 
22 void arch_invalidate_pmem(void *addr, size_t size)
23 {
24 	unsigned long start = (unsigned long) addr;
25 	flush_dcache_range(start, start + size);
26 }
27 EXPORT_SYMBOL_GPL(arch_invalidate_pmem);
28 
29 /*
30  * CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE symbols
31  */
32 long __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);
38 	flush_dcache_range(start, start + size);
39 
40 	return copied;
41 }
42 
43 void *memcpy_flushcache(void *dest, const void *src, size_t size)
44 {
45 	unsigned long start = (unsigned long) dest;
46 
47 	memcpy(dest, src, size);
48 	flush_dcache_range(start, start + size);
49 
50 	return dest;
51 }
52 EXPORT_SYMBOL(memcpy_flushcache);
53 
54 void 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 }
59 EXPORT_SYMBOL(memcpy_page_flushcache);
60