1 /* SPDX-License-Identifier: GPL-2.0 */
7 #include <linux/radix-tree.h>
9 /* Flag for synchronous flush */
10 #define DAXDEV_F_SYNC (1UL << 0)
12 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,
37 /* zero_page_range: required operation. Zero page range */
38 int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
41 extern struct attribute_group dax_attribute_group;
43 #if IS_ENABLED(CONFIG_DAX)
44 struct dax_device *dax_get_by_host(const char *host);
45 struct dax_device *alloc_dax(void *private, const char *host,
46 const struct dax_operations *ops, unsigned long flags);
47 void put_dax(struct dax_device *dax_dev);
48 void kill_dax(struct dax_device *dax_dev);
49 void dax_write_cache(struct dax_device *dax_dev, bool wc);
50 bool dax_write_cache_enabled(struct dax_device *dax_dev);
51 bool __dax_synchronous(struct dax_device *dax_dev);
52 static inline bool dax_synchronous(struct dax_device *dax_dev)
54 return __dax_synchronous(dax_dev);
56 void __set_dax_synchronous(struct dax_device *dax_dev);
57 static inline void set_dax_synchronous(struct dax_device *dax_dev)
59 __set_dax_synchronous(dax_dev);
62 * Check if given mapping is supported by the file / underlying device.
64 static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
65 struct dax_device *dax_dev)
67 if (!(vma->vm_flags & VM_SYNC))
69 if (!IS_DAX(file_inode(vma->vm_file)))
71 return dax_synchronous(dax_dev);
74 static inline struct dax_device *dax_get_by_host(const char *host)
78 static inline struct dax_device *alloc_dax(void *private, const char *host,
79 const struct dax_operations *ops, unsigned long flags)
82 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
83 * NULL is an error or expected.
87 static inline void put_dax(struct dax_device *dax_dev)
90 static inline void kill_dax(struct dax_device *dax_dev)
93 static inline void dax_write_cache(struct dax_device *dax_dev, bool wc)
96 static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)
100 static inline bool dax_synchronous(struct dax_device *dax_dev)
104 static inline void set_dax_synchronous(struct dax_device *dax_dev)
107 static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
108 struct dax_device *dax_dev)
110 return !(vma->vm_flags & VM_SYNC);
114 struct writeback_control;
115 int bdev_dax_pgoff(struct block_device *, sector_t, size_t, pgoff_t *pgoff);
116 #if IS_ENABLED(CONFIG_FS_DAX)
117 bool __bdev_dax_supported(struct block_device *bdev, int blocksize);
118 static inline bool bdev_dax_supported(struct block_device *bdev, int blocksize)
120 return __bdev_dax_supported(bdev, blocksize);
123 bool __generic_fsdax_supported(struct dax_device *dax_dev,
124 struct block_device *bdev, int blocksize, sector_t start,
126 static inline bool generic_fsdax_supported(struct dax_device *dax_dev,
127 struct block_device *bdev, int blocksize, sector_t start,
130 return __generic_fsdax_supported(dax_dev, bdev, blocksize, start,
134 static inline void fs_put_dax(struct dax_device *dax_dev)
139 struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev);
140 int dax_writeback_mapping_range(struct address_space *mapping,
141 struct dax_device *dax_dev, struct writeback_control *wbc);
143 struct page *dax_layout_busy_page(struct address_space *mapping);
144 dax_entry_t dax_lock_page(struct page *page);
145 void dax_unlock_page(struct page *page, dax_entry_t cookie);
147 static inline bool bdev_dax_supported(struct block_device *bdev,
153 static inline bool generic_fsdax_supported(struct dax_device *dax_dev,
154 struct block_device *bdev, int blocksize, sector_t start,
160 static inline void fs_put_dax(struct dax_device *dax_dev)
164 static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev)
169 static inline struct page *dax_layout_busy_page(struct address_space *mapping)
174 static inline int dax_writeback_mapping_range(struct address_space *mapping,
175 struct dax_device *dax_dev, struct writeback_control *wbc)
180 static inline dax_entry_t dax_lock_page(struct page *page)
182 if (IS_DAX(page->mapping->host))
187 static inline void dax_unlock_page(struct page *page, dax_entry_t cookie)
192 int dax_read_lock(void);
193 void dax_read_unlock(int id);
194 bool dax_alive(struct dax_device *dax_dev);
195 void *dax_get_private(struct dax_device *dax_dev);
196 long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
197 void **kaddr, pfn_t *pfn);
198 bool dax_supported(struct dax_device *dax_dev, struct block_device *bdev,
199 int blocksize, sector_t start, sector_t len);
200 size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
201 size_t bytes, struct iov_iter *i);
202 size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
203 size_t bytes, struct iov_iter *i);
204 int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
206 void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
208 ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
209 const struct iomap_ops *ops);
210 vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
211 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
212 vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
213 enum page_entry_size pe_size, pfn_t pfn);
214 int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
215 int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
217 int dax_iomap_zero(loff_t pos, unsigned offset, unsigned size,
218 struct iomap *iomap);
219 static inline bool dax_mapping(struct address_space *mapping)
221 return mapping->host && IS_DAX(mapping->host);