xref: /openbmc/linux/arch/powerpc/lib/pmem.c (revision 3213486f)
1 /*
2  * Copyright(c) 2017 IBM Corporation. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  */
13 
14 #include <linux/string.h>
15 #include <linux/export.h>
16 #include <linux/uaccess.h>
17 
18 #include <asm/cacheflush.h>
19 
20 /*
21  * CONFIG_ARCH_HAS_PMEM_API symbols
22  */
23 void arch_wb_cache_pmem(void *addr, size_t size)
24 {
25 	unsigned long start = (unsigned long) addr;
26 	flush_inval_dcache_range(start, start + size);
27 }
28 EXPORT_SYMBOL(arch_wb_cache_pmem);
29 
30 void arch_invalidate_pmem(void *addr, size_t size)
31 {
32 	unsigned long start = (unsigned long) addr;
33 	flush_inval_dcache_range(start, start + size);
34 }
35 EXPORT_SYMBOL(arch_invalidate_pmem);
36 
37 /*
38  * CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE symbols
39  */
40 long __copy_from_user_flushcache(void *dest, const void __user *src,
41 		unsigned size)
42 {
43 	unsigned long copied, start = (unsigned long) dest;
44 
45 	copied = __copy_from_user(dest, src, size);
46 	flush_inval_dcache_range(start, start + size);
47 
48 	return copied;
49 }
50 
51 void *memcpy_flushcache(void *dest, const void *src, size_t size)
52 {
53 	unsigned long start = (unsigned long) dest;
54 
55 	memcpy(dest, src, size);
56 	flush_inval_dcache_range(start, start + size);
57 
58 	return dest;
59 }
60 EXPORT_SYMBOL(memcpy_flushcache);
61 
62 void memcpy_page_flushcache(char *to, struct page *page, size_t offset,
63 	size_t len)
64 {
65 	memcpy_flushcache(to, page_to_virt(page) + offset, len);
66 }
67 EXPORT_SYMBOL(memcpy_page_flushcache);
68