1 /* SPDX-License-Identifier: GPL-2.0 */
7 #include <linux/radix-tree.h>
8 #include <asm/pgtable.h>
10 /* Flag for synchronous flush */
11 #define DAXDEV_F_SYNC (1UL << 0)
13 typedef unsigned long dax_entry_t;
17 struct dax_operations {
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.
23 long (*direct_access)(struct dax_device *, pgoff_t, long,
26 * Validate whether this device is usable as an fsdax backing
29 bool (*dax_supported)(struct dax_device *, struct block_device *, int,
31 /* copy_from_iter: required operation for fs-dax direct-i/o */
32 size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t,
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,
39 extern struct attribute_group dax_attribute_group;
41 #if IS_ENABLED(CONFIG_DAX)
42 struct dax_device *dax_get_by_host(const char *host);
43 struct dax_device *alloc_dax(void *private, const char *host,
44 const struct dax_operations *ops, unsigned long flags);
45 void put_dax(struct dax_device *dax_dev);
46 void kill_dax(struct dax_device *dax_dev);
47 void dax_write_cache(struct dax_device *dax_dev, bool wc);
48 bool dax_write_cache_enabled(struct dax_device *dax_dev);
49 bool __dax_synchronous(struct dax_device *dax_dev);
50 static inline bool dax_synchronous(struct dax_device *dax_dev)
52 return __dax_synchronous(dax_dev);
54 void __set_dax_synchronous(struct dax_device *dax_dev);
55 static inline void set_dax_synchronous(struct dax_device *dax_dev)
57 __set_dax_synchronous(dax_dev);
60 * Check if given mapping is supported by the file / underlying device.
62 static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
63 struct dax_device *dax_dev)
65 if (!(vma->vm_flags & VM_SYNC))
67 if (!IS_DAX(file_inode(vma->vm_file)))
69 return dax_synchronous(dax_dev);
72 static inline struct dax_device *dax_get_by_host(const char *host)
76 static inline struct dax_device *alloc_dax(void *private, const char *host,
77 const struct dax_operations *ops, unsigned long flags)
80 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
81 * NULL is an error or expected.
85 static inline void put_dax(struct dax_device *dax_dev)
88 static inline void kill_dax(struct dax_device *dax_dev)
91 static inline void dax_write_cache(struct dax_device *dax_dev, bool wc)
94 static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)
98 static inline bool dax_synchronous(struct dax_device *dax_dev)
102 static inline void set_dax_synchronous(struct dax_device *dax_dev)
105 static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
106 struct dax_device *dax_dev)
108 return !(vma->vm_flags & VM_SYNC);
112 struct writeback_control;
113 int bdev_dax_pgoff(struct block_device *, sector_t, size_t, pgoff_t *pgoff);
114 #if IS_ENABLED(CONFIG_FS_DAX)
115 bool __bdev_dax_supported(struct block_device *bdev, int blocksize);
116 static inline bool bdev_dax_supported(struct block_device *bdev, int blocksize)
118 return __bdev_dax_supported(bdev, blocksize);
121 bool __generic_fsdax_supported(struct dax_device *dax_dev,
122 struct block_device *bdev, int blocksize, sector_t start,
124 static inline bool generic_fsdax_supported(struct dax_device *dax_dev,
125 struct block_device *bdev, int blocksize, sector_t start,
128 return __generic_fsdax_supported(dax_dev, bdev, blocksize, start,
132 static inline struct dax_device *fs_dax_get_by_host(const char *host)
134 return dax_get_by_host(host);
137 static inline void fs_put_dax(struct dax_device *dax_dev)
142 struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev);
143 int dax_writeback_mapping_range(struct address_space *mapping,
144 struct block_device *bdev, struct writeback_control *wbc);
146 struct page *dax_layout_busy_page(struct address_space *mapping);
147 dax_entry_t dax_lock_page(struct page *page);
148 void dax_unlock_page(struct page *page, dax_entry_t cookie);
150 static inline bool bdev_dax_supported(struct block_device *bdev,
156 static inline bool generic_fsdax_supported(struct dax_device *dax_dev,
157 struct block_device *bdev, int blocksize, sector_t start,
163 static inline struct dax_device *fs_dax_get_by_host(const char *host)
168 static inline void fs_put_dax(struct dax_device *dax_dev)
172 static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev)
177 static inline struct page *dax_layout_busy_page(struct address_space *mapping)
182 static inline int dax_writeback_mapping_range(struct address_space *mapping,
183 struct block_device *bdev, struct writeback_control *wbc)
188 static inline dax_entry_t dax_lock_page(struct page *page)
190 if (IS_DAX(page->mapping->host))
195 static inline void dax_unlock_page(struct page *page, dax_entry_t cookie)
200 int dax_read_lock(void);
201 void dax_read_unlock(int id);
202 bool dax_alive(struct dax_device *dax_dev);
203 void *dax_get_private(struct dax_device *dax_dev);
204 long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
205 void **kaddr, pfn_t *pfn);
206 bool dax_supported(struct dax_device *dax_dev, struct block_device *bdev,
207 int blocksize, sector_t start, sector_t len);
208 size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
209 size_t bytes, struct iov_iter *i);
210 size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
211 size_t bytes, struct iov_iter *i);
212 void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
214 ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
215 const struct iomap_ops *ops);
216 vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
217 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
218 vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
219 enum page_entry_size pe_size, pfn_t pfn);
220 int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
221 int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
225 int __dax_zero_page_range(struct block_device *bdev,
226 struct dax_device *dax_dev, sector_t sector,
227 unsigned int offset, unsigned int length);
229 static inline int __dax_zero_page_range(struct block_device *bdev,
230 struct dax_device *dax_dev, sector_t sector,
231 unsigned int offset, unsigned int length)
237 static inline bool dax_mapping(struct address_space *mapping)
239 return mapping->host && IS_DAX(mapping->host);