aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/pmem.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/pmem.h')
-rw-r--r--include/linux/pmem.h70
1 files changed, 17 insertions, 53 deletions
diff --git a/include/linux/pmem.h b/include/linux/pmem.h
index 9e3ea94b8157..e856c2cb0fe8 100644
--- a/include/linux/pmem.h
+++ b/include/linux/pmem.h
@@ -26,37 +26,35 @@
26 * calling these symbols with arch_has_pmem_api() and redirect to the 26 * calling these symbols with arch_has_pmem_api() and redirect to the
27 * implementation in asm/pmem.h. 27 * implementation in asm/pmem.h.
28 */ 28 */
29static inline void arch_memcpy_to_pmem(void __pmem *dst, const void *src, 29static inline void arch_memcpy_to_pmem(void *dst, const void *src, size_t n)
30 size_t n)
31{ 30{
32 BUG(); 31 BUG();
33} 32}
34 33
35static inline int arch_memcpy_from_pmem(void *dst, const void __pmem *src, 34static inline int arch_memcpy_from_pmem(void *dst, const void *src, size_t n)
36 size_t n)
37{ 35{
38 BUG(); 36 BUG();
39 return -EFAULT; 37 return -EFAULT;
40} 38}
41 39
42static inline size_t arch_copy_from_iter_pmem(void __pmem *addr, size_t bytes, 40static inline size_t arch_copy_from_iter_pmem(void *addr, size_t bytes,
43 struct iov_iter *i) 41 struct iov_iter *i)
44{ 42{
45 BUG(); 43 BUG();
46 return 0; 44 return 0;
47} 45}
48 46
49static inline void arch_clear_pmem(void __pmem *addr, size_t size) 47static inline void arch_clear_pmem(void *addr, size_t size)
50{ 48{
51 BUG(); 49 BUG();
52} 50}
53 51
54static inline void arch_wb_cache_pmem(void __pmem *addr, size_t size) 52static inline void arch_wb_cache_pmem(void *addr, size_t size)
55{ 53{
56 BUG(); 54 BUG();
57} 55}
58 56
59static inline void arch_invalidate_pmem(void __pmem *addr, size_t size) 57static inline void arch_invalidate_pmem(void *addr, size_t size)
60{ 58{
61 BUG(); 59 BUG();
62} 60}
@@ -67,13 +65,6 @@ static inline bool arch_has_pmem_api(void)
67 return IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API); 65 return IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API);
68} 66}
69 67
70static inline int default_memcpy_from_pmem(void *dst, void __pmem const *src,
71 size_t size)
72{
73 memcpy(dst, (void __force *) src, size);
74 return 0;
75}
76
77/* 68/*
78 * memcpy_from_pmem - read from persistent memory with error handling 69 * memcpy_from_pmem - read from persistent memory with error handling
79 * @dst: destination buffer 70 * @dst: destination buffer
@@ -82,40 +73,13 @@ static inline int default_memcpy_from_pmem(void *dst, void __pmem const *src,
82 * 73 *
83 * Returns 0 on success negative error code on failure. 74 * Returns 0 on success negative error code on failure.
84 */ 75 */
85static inline int memcpy_from_pmem(void *dst, void __pmem const *src, 76static inline int memcpy_from_pmem(void *dst, void const *src, size_t size)
86 size_t size)
87{ 77{
88 if (arch_has_pmem_api()) 78 if (arch_has_pmem_api())
89 return arch_memcpy_from_pmem(dst, src, size); 79 return arch_memcpy_from_pmem(dst, src, size);
90 else 80 else
91 return default_memcpy_from_pmem(dst, src, size); 81 memcpy(dst, src, size);
92} 82 return 0;
93
94/*
95 * These defaults seek to offer decent performance and minimize the
96 * window between i/o completion and writes being durable on media.
97 * However, it is undefined / architecture specific whether
98 * ARCH_MEMREMAP_PMEM + default_memcpy_to_pmem is sufficient for
99 * making data durable relative to i/o completion.
100 */
101static inline void default_memcpy_to_pmem(void __pmem *dst, const void *src,
102 size_t size)
103{
104 memcpy((void __force *) dst, src, size);
105}
106
107static inline size_t default_copy_from_iter_pmem(void __pmem *addr,
108 size_t bytes, struct iov_iter *i)
109{
110 return copy_from_iter_nocache((void __force *)addr, bytes, i);
111}
112
113static inline void default_clear_pmem(void __pmem *addr, size_t size)
114{
115 if (size == PAGE_SIZE && ((unsigned long)addr & ~PAGE_MASK) == 0)
116 clear_page((void __force *)addr);
117 else
118 memset((void __force *)addr, 0, size);
119} 83}
120 84
121/** 85/**
@@ -130,12 +94,12 @@ static inline void default_clear_pmem(void __pmem *addr, size_t size)
130 * data may still reside in cpu or platform buffers, so this operation 94 * data may still reside in cpu or platform buffers, so this operation
131 * must be followed by a blkdev_issue_flush() on the pmem block device. 95 * must be followed by a blkdev_issue_flush() on the pmem block device.
132 */ 96 */
133static inline void memcpy_to_pmem(void __pmem *dst, const void *src, size_t n) 97static inline void memcpy_to_pmem(void *dst, const void *src, size_t n)
134{ 98{
135 if (arch_has_pmem_api()) 99 if (arch_has_pmem_api())
136 arch_memcpy_to_pmem(dst, src, n); 100 arch_memcpy_to_pmem(dst, src, n);
137 else 101 else
138 default_memcpy_to_pmem(dst, src, n); 102 memcpy(dst, src, n);
139} 103}
140 104
141/** 105/**
@@ -147,12 +111,12 @@ static inline void memcpy_to_pmem(void __pmem *dst, const void *src, size_t n)
147 * Copy data from the iterator 'i' to the PMEM buffer starting at 'addr'. 111 * Copy data from the iterator 'i' to the PMEM buffer starting at 'addr'.
148 * See blkdev_issue_flush() note for memcpy_to_pmem(). 112 * See blkdev_issue_flush() note for memcpy_to_pmem().
149 */ 113 */
150static inline size_t copy_from_iter_pmem(void __pmem *addr, size_t bytes, 114static inline size_t copy_from_iter_pmem(void *addr, size_t bytes,
151 struct iov_iter *i) 115 struct iov_iter *i)
152{ 116{
153 if (arch_has_pmem_api()) 117 if (arch_has_pmem_api())
154 return arch_copy_from_iter_pmem(addr, bytes, i); 118 return arch_copy_from_iter_pmem(addr, bytes, i);
155 return default_copy_from_iter_pmem(addr, bytes, i); 119 return copy_from_iter_nocache(addr, bytes, i);
156} 120}
157 121
158/** 122/**
@@ -163,12 +127,12 @@ static inline size_t copy_from_iter_pmem(void __pmem *addr, size_t bytes,
163 * Write zeros into the memory range starting at 'addr' for 'size' bytes. 127 * Write zeros into the memory range starting at 'addr' for 'size' bytes.
164 * See blkdev_issue_flush() note for memcpy_to_pmem(). 128 * See blkdev_issue_flush() note for memcpy_to_pmem().
165 */ 129 */
166static inline void clear_pmem(void __pmem *addr, size_t size) 130static inline void clear_pmem(void *addr, size_t size)
167{ 131{
168 if (arch_has_pmem_api()) 132 if (arch_has_pmem_api())
169 arch_clear_pmem(addr, size); 133 arch_clear_pmem(addr, size);
170 else 134 else
171 default_clear_pmem(addr, size); 135 memset(addr, 0, size);
172} 136}
173 137
174/** 138/**
@@ -179,7 +143,7 @@ static inline void clear_pmem(void __pmem *addr, size_t size)
179 * For platforms that support clearing poison this flushes any poisoned 143 * For platforms that support clearing poison this flushes any poisoned
180 * ranges out of the cache 144 * ranges out of the cache
181 */ 145 */
182static inline void invalidate_pmem(void __pmem *addr, size_t size) 146static inline void invalidate_pmem(void *addr, size_t size)
183{ 147{
184 if (arch_has_pmem_api()) 148 if (arch_has_pmem_api())
185 arch_invalidate_pmem(addr, size); 149 arch_invalidate_pmem(addr, size);
@@ -193,7 +157,7 @@ static inline void invalidate_pmem(void __pmem *addr, size_t size)
193 * Write back the processor cache range starting at 'addr' for 'size' bytes. 157 * Write back the processor cache range starting at 'addr' for 'size' bytes.
194 * See blkdev_issue_flush() note for memcpy_to_pmem(). 158 * See blkdev_issue_flush() note for memcpy_to_pmem().
195 */ 159 */
196static inline void wb_cache_pmem(void __pmem *addr, size_t size) 160static inline void wb_cache_pmem(void *addr, size_t size)
197{ 161{
198 if (arch_has_pmem_api()) 162 if (arch_has_pmem_api())
199 arch_wb_cache_pmem(addr, size); 163 arch_wb_cache_pmem(addr, size);