]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/pmem.h
x86, dax, libnvdimm: remove wb_cache_pmem() indirection
[karo-tx-linux.git] / include / linux / pmem.h
1 /*
2  * Copyright(c) 2015 Intel 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 #ifndef __PMEM_H__
14 #define __PMEM_H__
15
16 #include <linux/io.h>
17 #include <linux/uio.h>
18
19 #ifdef CONFIG_ARCH_HAS_PMEM_API
20 #define ARCH_MEMREMAP_PMEM MEMREMAP_WB
21 #include <asm/pmem.h>
22 #else
23 #define ARCH_MEMREMAP_PMEM MEMREMAP_WT
24 /*
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.
28  */
29 static inline void arch_memcpy_to_pmem(void *dst, const void *src, size_t n)
30 {
31         BUG();
32 }
33
34 static inline void arch_invalidate_pmem(void *addr, size_t size)
35 {
36         BUG();
37 }
38 #endif
39
40 static inline bool arch_has_pmem_api(void)
41 {
42         return IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API);
43 }
44
45 /**
46  * memcpy_to_pmem - copy data to persistent memory
47  * @dst: destination buffer for the copy
48  * @src: source buffer for the copy
49  * @n: length of the copy in bytes
50  *
51  * Perform a memory copy that results in the destination of the copy
52  * being effectively evicted from, or never written to, the processor
53  * cache hierarchy after the copy completes.  After memcpy_to_pmem()
54  * data may still reside in cpu or platform buffers, so this operation
55  * must be followed by a blkdev_issue_flush() on the pmem block device.
56  */
57 static inline void memcpy_to_pmem(void *dst, const void *src, size_t n)
58 {
59         if (arch_has_pmem_api())
60                 arch_memcpy_to_pmem(dst, src, n);
61         else
62                 memcpy(dst, src, n);
63 }
64
65 /**
66  * invalidate_pmem - flush a pmem range from the cache hierarchy
67  * @addr:       virtual start address
68  * @size:       bytes to invalidate (internally aligned to cache line size)
69  *
70  * For platforms that support clearing poison this flushes any poisoned
71  * ranges out of the cache
72  */
73 static inline void invalidate_pmem(void *addr, size_t size)
74 {
75         if (arch_has_pmem_api())
76                 arch_invalidate_pmem(addr, size);
77 }
78 #endif /* __PMEM_H__ */