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 int arch_memcpy_from_pmem(void *dst
, const void *src
, size_t n
)
40 static inline size_t arch_copy_from_iter_pmem(void *addr
, size_t bytes
,
47 static inline void arch_clear_pmem(void *addr
, size_t size
)
52 static inline void arch_wb_cache_pmem(void *addr
, size_t size
)
57 static inline void arch_invalidate_pmem(void *addr
, size_t size
)
63 static inline bool arch_has_pmem_api(void)
65 return IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API
);
69 * memcpy_from_pmem - read from persistent memory with error handling
70 * @dst: destination buffer
72 * @size: transfer length
74 * Returns 0 on success negative error code on failure.
76 static inline int memcpy_from_pmem(void *dst
, void const *src
, size_t size
)
78 if (arch_has_pmem_api())
79 return arch_memcpy_from_pmem(dst
, src
, size
);
81 memcpy(dst
, src
, size
);
86 * memcpy_to_pmem - copy data to persistent memory
87 * @dst: destination buffer for the copy
88 * @src: source buffer for the copy
89 * @n: length of the copy in bytes
91 * Perform a memory copy that results in the destination of the copy
92 * being effectively evicted from, or never written to, the processor
93 * cache hierarchy after the copy completes. After memcpy_to_pmem()
94 * data may still reside in cpu or platform buffers, so this operation
95 * must be followed by a blkdev_issue_flush() on the pmem block device.
97 static inline void memcpy_to_pmem(void *dst
, const void *src
, size_t n
)
99 if (arch_has_pmem_api())
100 arch_memcpy_to_pmem(dst
, src
, n
);
106 * copy_from_iter_pmem - copy data from an iterator to PMEM
107 * @addr: PMEM destination address
108 * @bytes: number of bytes to copy
109 * @i: iterator with source data
111 * Copy data from the iterator 'i' to the PMEM buffer starting at 'addr'.
112 * See blkdev_issue_flush() note for memcpy_to_pmem().
114 static inline size_t copy_from_iter_pmem(void *addr
, size_t bytes
,
117 if (arch_has_pmem_api())
118 return arch_copy_from_iter_pmem(addr
, bytes
, i
);
119 return copy_from_iter_nocache(addr
, bytes
, i
);
123 * clear_pmem - zero a PMEM memory range
124 * @addr: virtual start address
125 * @size: number of bytes to zero
127 * Write zeros into the memory range starting at 'addr' for 'size' bytes.
128 * See blkdev_issue_flush() note for memcpy_to_pmem().
130 static inline void clear_pmem(void *addr
, size_t size
)
132 if (arch_has_pmem_api())
133 arch_clear_pmem(addr
, size
);
135 memset(addr
, 0, size
);
139 * invalidate_pmem - flush a pmem range from the cache hierarchy
140 * @addr: virtual start address
141 * @size: bytes to invalidate (internally aligned to cache line size)
143 * For platforms that support clearing poison this flushes any poisoned
144 * ranges out of the cache
146 static inline void invalidate_pmem(void *addr
, size_t size
)
148 if (arch_has_pmem_api())
149 arch_invalidate_pmem(addr
, size
);
153 * wb_cache_pmem - write back processor cache for PMEM memory range
154 * @addr: virtual start address
155 * @size: number of bytes to write back
157 * Write back the processor cache range starting at 'addr' for 'size' bytes.
158 * See blkdev_issue_flush() note for memcpy_to_pmem().
160 static inline void wb_cache_pmem(void *addr
, size_t size
)
162 if (arch_has_pmem_api())
163 arch_wb_cache_pmem(addr
, size
);
165 #endif /* __PMEM_H__ */