2 * Copyright(c) 2015 Intel Corporation. All rights reserved.
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.
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.
17 #include <linux/uio.h>
19 #ifdef CONFIG_ARCH_HAS_PMEM_API
20 #define ARCH_MEMREMAP_PMEM MEMREMAP_WB
23 #define ARCH_MEMREMAP_PMEM MEMREMAP_WT
25 * These are simply here to enable compilation, all call sites gate
26 * calling these symbols with arch_has_pmem_api() and redirect to the
27 * implementation in asm/pmem.h.
29 static inline void arch_memcpy_to_pmem(void *dst, const void *src, size_t n)
34 static inline size_t arch_copy_from_iter_pmem(void *addr, size_t bytes,
41 static inline void arch_clear_pmem(void *addr, size_t size)
46 static inline void arch_wb_cache_pmem(void *addr, size_t size)
51 static inline void arch_invalidate_pmem(void *addr, size_t size)
57 static inline bool arch_has_pmem_api(void)
59 return IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API);
63 * memcpy_to_pmem - copy data to persistent memory
64 * @dst: destination buffer for the copy
65 * @src: source buffer for the copy
66 * @n: length of the copy in bytes
68 * Perform a memory copy that results in the destination of the copy
69 * being effectively evicted from, or never written to, the processor
70 * cache hierarchy after the copy completes. After memcpy_to_pmem()
71 * data may still reside in cpu or platform buffers, so this operation
72 * must be followed by a blkdev_issue_flush() on the pmem block device.
74 static inline void memcpy_to_pmem(void *dst, const void *src, size_t n)
76 if (arch_has_pmem_api())
77 arch_memcpy_to_pmem(dst, src, n);
83 * copy_from_iter_pmem - copy data from an iterator to PMEM
84 * @addr: PMEM destination address
85 * @bytes: number of bytes to copy
86 * @i: iterator with source data
88 * Copy data from the iterator 'i' to the PMEM buffer starting at 'addr'.
89 * See blkdev_issue_flush() note for memcpy_to_pmem().
91 static inline size_t copy_from_iter_pmem(void *addr, size_t bytes,
94 if (arch_has_pmem_api())
95 return arch_copy_from_iter_pmem(addr, bytes, i);
96 return copy_from_iter_nocache(addr, bytes, i);
100 * clear_pmem - zero a PMEM memory range
101 * @addr: virtual start address
102 * @size: number of bytes to zero
104 * Write zeros into the memory range starting at 'addr' for 'size' bytes.
105 * See blkdev_issue_flush() note for memcpy_to_pmem().
107 static inline void clear_pmem(void *addr, size_t size)
109 if (arch_has_pmem_api())
110 arch_clear_pmem(addr, size);
112 memset(addr, 0, size);
116 * invalidate_pmem - flush a pmem range from the cache hierarchy
117 * @addr: virtual start address
118 * @size: bytes to invalidate (internally aligned to cache line size)
120 * For platforms that support clearing poison this flushes any poisoned
121 * ranges out of the cache
123 static inline void invalidate_pmem(void *addr, size_t size)
125 if (arch_has_pmem_api())
126 arch_invalidate_pmem(addr, size);
130 * wb_cache_pmem - write back processor cache for PMEM memory range
131 * @addr: virtual start address
132 * @size: number of bytes to write back
134 * Write back the processor cache range starting at 'addr' for 'size' bytes.
135 * See blkdev_issue_flush() note for memcpy_to_pmem().
137 static inline void wb_cache_pmem(void *addr, size_t size)
139 if (arch_has_pmem_api())
140 arch_wb_cache_pmem(addr, size);
142 #endif /* __PMEM_H__ */