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 *alloc_dax(void *private, const char *host,
45 const struct dax_operations *ops, unsigned long flags);
46 void put_dax(struct dax_device *dax_dev);
47 void kill_dax(struct dax_device *dax_dev);
48 void dax_write_cache(struct dax_device *dax_dev, bool wc);
49 bool dax_write_cache_enabled(struct dax_device *dax_dev);
50 bool __dax_synchronous(struct dax_device *dax_dev);
51 static inline bool dax_synchronous(struct dax_device *dax_dev)
53 return __dax_synchronous(dax_dev);
55 void __set_dax_synchronous(struct dax_device *dax_dev);
56 static inline void set_dax_synchronous(struct dax_device *dax_dev)
58 __set_dax_synchronous(dax_dev);
61 * Check if given mapping is supported by the file / underlying device.
63 static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
64 struct dax_device *dax_dev)
66 if (!(vma->vm_flags & VM_SYNC))
68 if (!IS_DAX(file_inode(vma->vm_file)))
70 return dax_synchronous(dax_dev);
73 static inline struct dax_device *alloc_dax(void *private, const char *host,
74 const struct dax_operations *ops, unsigned long flags)
77 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
78 * NULL is an error or expected.
82 static inline void put_dax(struct dax_device *dax_dev)
85 static inline void kill_dax(struct dax_device *dax_dev)
88 static inline void dax_write_cache(struct dax_device *dax_dev, bool wc)
91 static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)
95 static inline bool dax_synchronous(struct dax_device *dax_dev)
99 static inline void set_dax_synchronous(struct dax_device *dax_dev)
102 static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
103 struct dax_device *dax_dev)
105 return !(vma->vm_flags & VM_SYNC);
109 struct writeback_control;
110 int bdev_dax_pgoff(struct block_device *, sector_t, size_t, pgoff_t *pgoff);
111 #if IS_ENABLED(CONFIG_FS_DAX)
112 bool generic_fsdax_supported(struct dax_device *dax_dev,
113 struct block_device *bdev, int blocksize, sector_t start,
116 bool dax_supported(struct dax_device *dax_dev, struct block_device *bdev,
117 int blocksize, sector_t start, sector_t len);
119 static inline void fs_put_dax(struct dax_device *dax_dev)
124 struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev);
125 int dax_writeback_mapping_range(struct address_space *mapping,
126 struct dax_device *dax_dev, struct writeback_control *wbc);
128 struct page *dax_layout_busy_page(struct address_space *mapping);
129 struct page *dax_layout_busy_page_range(struct address_space *mapping, loff_t start, loff_t end);
130 dax_entry_t dax_lock_page(struct page *page);
131 void dax_unlock_page(struct page *page, dax_entry_t cookie);
133 #define generic_fsdax_supported NULL
135 static inline bool dax_supported(struct dax_device *dax_dev,
136 struct block_device *bdev, int blocksize, sector_t start,
142 static inline void fs_put_dax(struct dax_device *dax_dev)
146 static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev)
151 static inline struct page *dax_layout_busy_page(struct address_space *mapping)
156 static inline struct page *dax_layout_busy_page_range(struct address_space *mapping, pgoff_t start, pgoff_t nr_pages)
161 static inline int dax_writeback_mapping_range(struct address_space *mapping,
162 struct dax_device *dax_dev, struct writeback_control *wbc)
167 static inline dax_entry_t dax_lock_page(struct page *page)
169 if (IS_DAX(page->mapping->host))
174 static inline void dax_unlock_page(struct page *page, dax_entry_t cookie)
179 #if IS_ENABLED(CONFIG_DAX)
180 int dax_read_lock(void);
181 void dax_read_unlock(int id);
183 static inline int dax_read_lock(void)
188 static inline void dax_read_unlock(int id)
191 #endif /* CONFIG_DAX */
192 bool dax_alive(struct dax_device *dax_dev);
193 void *dax_get_private(struct dax_device *dax_dev);
194 long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
195 void **kaddr, pfn_t *pfn);
196 size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
197 size_t bytes, struct iov_iter *i);
198 size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
199 size_t bytes, struct iov_iter *i);
200 int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
202 void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
204 ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
205 const struct iomap_ops *ops);
206 vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
207 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
208 vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
209 enum page_entry_size pe_size, pfn_t pfn);
210 int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
211 int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
213 s64 dax_iomap_zero(loff_t pos, u64 length, struct iomap *iomap);
214 static inline bool dax_mapping(struct address_space *mapping)
216 return mapping->host && IS_DAX(mapping->host);
219 #ifdef CONFIG_DEV_DAX_HMEM_DEVICES
220 void hmem_register_device(int target_nid, struct resource *r);
222 static inline void hmem_register_device(int target_nid, struct resource *r)