dax: remove the DAXDEV_F_SYNC flag
[linux-block.git] / include / linux / dax.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
c94c2acf
MW
2#ifndef _LINUX_DAX_H
3#define _LINUX_DAX_H
4
5#include <linux/fs.h>
6#include <linux/mm.h>
4f622938 7#include <linux/radix-tree.h>
c94c2acf 8
27359fd6
MW
9typedef unsigned long dax_entry_t;
10
fb08a190
CH
11struct dax_device;
12struct gendisk;
a254e568 13struct iomap_ops;
c6f40468 14struct iomap_iter;
4f3b4f16 15struct iomap;
fb08a190 16
6568b08b
DW
17struct dax_operations {
18 /*
19 * direct_access: translate a device-relative
20 * logical-page-offset into an absolute physical pfn. Return the
21 * number of pages available for DAX at that pfn.
22 */
23 long (*direct_access)(struct dax_device *, pgoff_t, long,
24 void **, pfn_t *);
7bf7eac8
DW
25 /*
26 * Validate whether this device is usable as an fsdax backing
27 * device.
28 */
29 bool (*dax_supported)(struct dax_device *, struct block_device *, int,
30 sector_t, sector_t);
5d61e43b 31 /* copy_from_iter: required operation for fs-dax direct-i/o */
0aed55af
DW
32 size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t,
33 struct iov_iter *);
b3a9a0c3
DW
34 /* copy_to_iter: required operation for fs-dax direct-i/o */
35 size_t (*copy_to_iter)(struct dax_device *, pgoff_t, void *, size_t,
36 struct iov_iter *);
f605a263
VG
37 /* zero_page_range: required operation. Zero page range */
38 int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
6568b08b 39};
a254e568 40
f5705aa8 41#if IS_ENABLED(CONFIG_DAX)
30c6828a 42struct dax_device *alloc_dax(void *private, const struct dax_operations *ops);
f5705aa8 43void put_dax(struct dax_device *dax_dev);
976431b0
DW
44void kill_dax(struct dax_device *dax_dev);
45void dax_write_cache(struct dax_device *dax_dev, bool wc);
46bool dax_write_cache_enabled(struct dax_device *dax_dev);
fd1d00ec
CH
47bool dax_synchronous(struct dax_device *dax_dev);
48void set_dax_synchronous(struct dax_device *dax_dev);
32de1484
PG
49/*
50 * Check if given mapping is supported by the file / underlying device.
51 */
52static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
53 struct dax_device *dax_dev)
54{
55 if (!(vma->vm_flags & VM_SYNC))
56 return true;
57 if (!IS_DAX(file_inode(vma->vm_file)))
58 return false;
59 return dax_synchronous(dax_dev);
60}
f5705aa8 61#else
fb08a190 62static inline struct dax_device *alloc_dax(void *private,
30c6828a 63 const struct dax_operations *ops)
976431b0
DW
64{
65 /*
66 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
67 * NULL is an error or expected.
68 */
69 return NULL;
70}
f5705aa8
DW
71static inline void put_dax(struct dax_device *dax_dev)
72{
73}
976431b0
DW
74static inline void kill_dax(struct dax_device *dax_dev)
75{
76}
77static inline void dax_write_cache(struct dax_device *dax_dev, bool wc)
78{
79}
80static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)
81{
82 return false;
83}
fefc1d97
PG
84static inline bool dax_synchronous(struct dax_device *dax_dev)
85{
86 return true;
87}
88static inline void set_dax_synchronous(struct dax_device *dax_dev)
89{
90}
32de1484
PG
91static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
92 struct dax_device *dax_dev)
93{
94 return !(vma->vm_flags & VM_SYNC);
95}
f5705aa8
DW
96#endif
97
f44c7763 98struct writeback_control;
2ede8923 99#if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX)
fb08a190
CH
100int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk);
101void dax_remove_host(struct gendisk *disk);
2ede8923
CH
102struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev,
103 u64 *start_off);
f5705aa8
DW
104static inline void fs_put_dax(struct dax_device *dax_dev)
105{
106 put_dax(dax_dev);
107}
ef510424 108#else
fb08a190
CH
109static inline int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk)
110{
111 return 0;
112}
113static inline void dax_remove_host(struct gendisk *disk)
114{
115}
cd913c76
CH
116static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev,
117 u64 *start_off)
78f35473
DW
118{
119 return NULL;
120}
2ede8923
CH
121static inline void fs_put_dax(struct dax_device *dax_dev)
122{
123}
124#endif /* CONFIG_BLOCK && CONFIG_FS_DAX */
f44c7763 125
2ede8923
CH
126#if IS_ENABLED(CONFIG_FS_DAX)
127int dax_writeback_mapping_range(struct address_space *mapping,
128 struct dax_device *dax_dev, struct writeback_control *wbc);
129
130struct page *dax_layout_busy_page(struct address_space *mapping);
131struct page *dax_layout_busy_page_range(struct address_space *mapping, loff_t start, loff_t end);
132dax_entry_t dax_lock_page(struct page *page);
133void dax_unlock_page(struct page *page, dax_entry_t cookie);
134#else
5fac7408
DW
135static inline struct page *dax_layout_busy_page(struct address_space *mapping)
136{
137 return NULL;
138}
139
6bbdd563
VG
140static inline struct page *dax_layout_busy_page_range(struct address_space *mapping, pgoff_t start, pgoff_t nr_pages)
141{
142 return NULL;
143}
144
f44c7763 145static inline int dax_writeback_mapping_range(struct address_space *mapping,
3f666c56 146 struct dax_device *dax_dev, struct writeback_control *wbc)
f44c7763
DW
147{
148 return -EOPNOTSUPP;
149}
c2a7d2a1 150
27359fd6 151static inline dax_entry_t dax_lock_page(struct page *page)
c2a7d2a1
DW
152{
153 if (IS_DAX(page->mapping->host))
27359fd6
MW
154 return ~0UL;
155 return 0;
c2a7d2a1
DW
156}
157
27359fd6 158static inline void dax_unlock_page(struct page *page, dax_entry_t cookie)
c2a7d2a1
DW
159{
160}
ef510424
DW
161#endif
162
c6f40468
CH
163int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
164 const struct iomap_ops *ops);
165int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
166 const struct iomap_ops *ops);
167
e2ec5128 168#if IS_ENABLED(CONFIG_DAX)
7b6be844
DW
169int dax_read_lock(void);
170void dax_read_unlock(int id);
e2ec5128
JK
171#else
172static inline int dax_read_lock(void)
173{
174 return 0;
175}
176
177static inline void dax_read_unlock(int id)
178{
179}
180#endif /* CONFIG_DAX */
c1d6e828 181bool dax_alive(struct dax_device *dax_dev);
c1d6e828 182void *dax_get_private(struct dax_device *dax_dev);
b0686260
DW
183long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
184 void **kaddr, pfn_t *pfn);
7e026c8c
DW
185size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
186 size_t bytes, struct iov_iter *i);
b3a9a0c3
DW
187size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
188 size_t bytes, struct iov_iter *i);
f605a263
VG
189int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
190 size_t nr_pages);
c3ca015f 191void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
7b6be844 192
11c59c92 193ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
8ff6daa1 194 const struct iomap_ops *ops);
f77bc3a8 195vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
c0b24625 196 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
ab77dab4
SJ
197vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
198 enum page_entry_size pe_size, pfn_t pfn);
ac401cc7 199int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
c6dcf52c
JK
200int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
201 pgoff_t index);
f9fe48be
RZ
202static inline bool dax_mapping(struct address_space *mapping)
203{
204 return mapping->host && IS_DAX(mapping->host);
205}
7f6d5b52 206
c01044cc
DW
207#ifdef CONFIG_DEV_DAX_HMEM_DEVICES
208void hmem_register_device(int target_nid, struct resource *r);
209#else
210static inline void hmem_register_device(int target_nid, struct resource *r)
211{
212}
213#endif
214
c94c2acf 215#endif