summaryrefslogtreecommitdiff
path: root/include/linux/pmem.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/pmem.h')
-rw-r--r--include/linux/pmem.h40
1 files changed, 30 insertions, 10 deletions
diff --git a/include/linux/pmem.h b/include/linux/pmem.h
index 3ec5309e29f3..57d146fe44dd 100644
--- a/include/linux/pmem.h
+++ b/include/linux/pmem.h
@@ -42,6 +42,13 @@ static inline void arch_memcpy_to_pmem(void __pmem *dst, const void *src,
BUG();
}
+static inline int arch_memcpy_from_pmem(void *dst, const void __pmem *src,
+ size_t n)
+{
+ BUG();
+ return -EFAULT;
+}
+
static inline size_t arch_copy_from_iter_pmem(void __pmem *addr, size_t bytes,
struct iov_iter *i)
{
@@ -65,20 +72,33 @@ static inline void arch_invalidate_pmem(void __pmem *addr, size_t size)
}
#endif
-/*
- * Architectures that define ARCH_HAS_PMEM_API must provide
- * implementations for arch_memcpy_to_pmem(), arch_wmb_pmem(),
- * arch_copy_from_iter_pmem(), arch_clear_pmem(), arch_wb_cache_pmem()
- * and arch_has_wmb_pmem().
- */
-static inline void memcpy_from_pmem(void *dst, void __pmem const *src, size_t size)
+static inline bool arch_has_pmem_api(void)
{
- memcpy(dst, (void __force const *) src, size);
+ return IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API);
}
-static inline bool arch_has_pmem_api(void)
+static inline int default_memcpy_from_pmem(void *dst, void __pmem const *src,
+ size_t size)
{
- return IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API);
+ memcpy(dst, (void __force *) src, size);
+ return 0;
+}
+
+/*
+ * memcpy_from_pmem - read from persistent memory with error handling
+ * @dst: destination buffer
+ * @src: source buffer
+ * @size: transfer length
+ *
+ * Returns 0 on success negative error code on failure.
+ */
+static inline int memcpy_from_pmem(void *dst, void __pmem const *src,
+ size_t size)
+{
+ if (arch_has_pmem_api())
+ return arch_memcpy_from_pmem(dst, src, size);
+ else
+ return default_memcpy_from_pmem(dst, src, size);
}
/**