1 /* SPDX-License-Identifier: GPL-2.0 */
7 #include <linux/radix-tree.h>
9 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 /* zero_page_range: required operation. Zero page range */
32 int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
35 #if IS_ENABLED(CONFIG_DAX)
36 struct dax_device *alloc_dax(void *private, const struct dax_operations *ops);
37 void put_dax(struct dax_device *dax_dev);
38 void kill_dax(struct dax_device *dax_dev);
39 void dax_write_cache(struct dax_device *dax_dev, bool wc);
40 bool dax_write_cache_enabled(struct dax_device *dax_dev);
41 bool dax_synchronous(struct dax_device *dax_dev);
42 void set_dax_synchronous(struct dax_device *dax_dev);
44 * Check if given mapping is supported by the file / underlying device.
46 static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
47 struct dax_device *dax_dev)
49 if (!(vma->vm_flags & VM_SYNC))
51 if (!IS_DAX(file_inode(vma->vm_file)))
53 return dax_synchronous(dax_dev);
56 static inline struct dax_device *alloc_dax(void *private,
57 const struct dax_operations *ops)
60 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
61 * NULL is an error or expected.
65 static inline void put_dax(struct dax_device *dax_dev)
68 static inline void kill_dax(struct dax_device *dax_dev)
71 static inline void dax_write_cache(struct dax_device *dax_dev, bool wc)
74 static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)
78 static inline bool dax_synchronous(struct dax_device *dax_dev)
82 static inline void set_dax_synchronous(struct dax_device *dax_dev)
85 static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
86 struct dax_device *dax_dev)
88 return !(vma->vm_flags & VM_SYNC);
92 void set_dax_nocache(struct dax_device *dax_dev);
93 void set_dax_nomc(struct dax_device *dax_dev);
95 struct writeback_control;
96 #if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX)
97 int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk);
98 void dax_remove_host(struct gendisk *disk);
99 struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev,
101 static inline void fs_put_dax(struct dax_device *dax_dev)
106 static inline int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk)
110 static inline void dax_remove_host(struct gendisk *disk)
113 static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev,
118 static inline void fs_put_dax(struct dax_device *dax_dev)
121 #endif /* CONFIG_BLOCK && CONFIG_FS_DAX */
123 #if IS_ENABLED(CONFIG_FS_DAX)
124 int dax_writeback_mapping_range(struct address_space *mapping,
125 struct dax_device *dax_dev, struct writeback_control *wbc);
127 struct page *dax_layout_busy_page(struct address_space *mapping);
128 struct page *dax_layout_busy_page_range(struct address_space *mapping, loff_t start, loff_t end);
129 dax_entry_t dax_lock_page(struct page *page);
130 void dax_unlock_page(struct page *page, dax_entry_t cookie);
132 static inline struct page *dax_layout_busy_page(struct address_space *mapping)
137 static inline struct page *dax_layout_busy_page_range(struct address_space *mapping, pgoff_t start, pgoff_t nr_pages)
142 static inline int dax_writeback_mapping_range(struct address_space *mapping,
143 struct dax_device *dax_dev, struct writeback_control *wbc)
148 static inline dax_entry_t dax_lock_page(struct page *page)
150 if (IS_DAX(page->mapping->host))
155 static inline void dax_unlock_page(struct page *page, dax_entry_t cookie)
160 int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
161 const struct iomap_ops *ops);
162 int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
163 const struct iomap_ops *ops);
165 #if IS_ENABLED(CONFIG_DAX)
166 int dax_read_lock(void);
167 void dax_read_unlock(int id);
169 static inline int dax_read_lock(void)
174 static inline void dax_read_unlock(int id)
177 #endif /* CONFIG_DAX */
178 bool dax_alive(struct dax_device *dax_dev);
179 void *dax_get_private(struct dax_device *dax_dev);
180 long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
181 void **kaddr, pfn_t *pfn);
182 size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
183 size_t bytes, struct iov_iter *i);
184 size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
185 size_t bytes, struct iov_iter *i);
186 int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
188 void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
190 ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
191 const struct iomap_ops *ops);
192 vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
193 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
194 vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
195 enum page_entry_size pe_size, pfn_t pfn);
196 int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
197 int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
199 static inline bool dax_mapping(struct address_space *mapping)
201 return mapping->host && IS_DAX(mapping->host);
204 #ifdef CONFIG_DEV_DAX_HMEM_DEVICES
205 void hmem_register_device(int target_nid, struct resource *r);
207 static inline void hmem_register_device(int target_nid, struct resource *r)