Merge tag 'platform-drivers-x86-v5.18-1' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / include / linux / dax.h
... / ...
CommitLineData
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_DAX_H
3#define _LINUX_DAX_H
4
5#include <linux/fs.h>
6#include <linux/mm.h>
7#include <linux/radix-tree.h>
8
9typedef unsigned long dax_entry_t;
10
11struct dax_device;
12struct gendisk;
13struct iomap_ops;
14struct iomap_iter;
15struct iomap;
16
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 *);
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);
31 /* zero_page_range: required operation. Zero page range */
32 int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
33};
34
35#if IS_ENABLED(CONFIG_DAX)
36struct dax_device *alloc_dax(void *private, const struct dax_operations *ops);
37void put_dax(struct dax_device *dax_dev);
38void kill_dax(struct dax_device *dax_dev);
39void dax_write_cache(struct dax_device *dax_dev, bool wc);
40bool dax_write_cache_enabled(struct dax_device *dax_dev);
41bool dax_synchronous(struct dax_device *dax_dev);
42void set_dax_synchronous(struct dax_device *dax_dev);
43/*
44 * Check if given mapping is supported by the file / underlying device.
45 */
46static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
47 struct dax_device *dax_dev)
48{
49 if (!(vma->vm_flags & VM_SYNC))
50 return true;
51 if (!IS_DAX(file_inode(vma->vm_file)))
52 return false;
53 return dax_synchronous(dax_dev);
54}
55#else
56static inline struct dax_device *alloc_dax(void *private,
57 const struct dax_operations *ops)
58{
59 /*
60 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
61 * NULL is an error or expected.
62 */
63 return NULL;
64}
65static inline void put_dax(struct dax_device *dax_dev)
66{
67}
68static inline void kill_dax(struct dax_device *dax_dev)
69{
70}
71static inline void dax_write_cache(struct dax_device *dax_dev, bool wc)
72{
73}
74static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)
75{
76 return false;
77}
78static inline bool dax_synchronous(struct dax_device *dax_dev)
79{
80 return true;
81}
82static inline void set_dax_synchronous(struct dax_device *dax_dev)
83{
84}
85static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
86 struct dax_device *dax_dev)
87{
88 return !(vma->vm_flags & VM_SYNC);
89}
90#endif
91
92void set_dax_nocache(struct dax_device *dax_dev);
93void set_dax_nomc(struct dax_device *dax_dev);
94
95struct writeback_control;
96#if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX)
97int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk);
98void dax_remove_host(struct gendisk *disk);
99struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev,
100 u64 *start_off);
101static inline void fs_put_dax(struct dax_device *dax_dev)
102{
103 put_dax(dax_dev);
104}
105#else
106static inline int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk)
107{
108 return 0;
109}
110static inline void dax_remove_host(struct gendisk *disk)
111{
112}
113static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev,
114 u64 *start_off)
115{
116 return NULL;
117}
118static inline void fs_put_dax(struct dax_device *dax_dev)
119{
120}
121#endif /* CONFIG_BLOCK && CONFIG_FS_DAX */
122
123#if IS_ENABLED(CONFIG_FS_DAX)
124int dax_writeback_mapping_range(struct address_space *mapping,
125 struct dax_device *dax_dev, struct writeback_control *wbc);
126
127struct page *dax_layout_busy_page(struct address_space *mapping);
128struct page *dax_layout_busy_page_range(struct address_space *mapping, loff_t start, loff_t end);
129dax_entry_t dax_lock_page(struct page *page);
130void dax_unlock_page(struct page *page, dax_entry_t cookie);
131#else
132static inline struct page *dax_layout_busy_page(struct address_space *mapping)
133{
134 return NULL;
135}
136
137static inline struct page *dax_layout_busy_page_range(struct address_space *mapping, pgoff_t start, pgoff_t nr_pages)
138{
139 return NULL;
140}
141
142static inline int dax_writeback_mapping_range(struct address_space *mapping,
143 struct dax_device *dax_dev, struct writeback_control *wbc)
144{
145 return -EOPNOTSUPP;
146}
147
148static inline dax_entry_t dax_lock_page(struct page *page)
149{
150 if (IS_DAX(page->mapping->host))
151 return ~0UL;
152 return 0;
153}
154
155static inline void dax_unlock_page(struct page *page, dax_entry_t cookie)
156{
157}
158#endif
159
160int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
161 const struct iomap_ops *ops);
162int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
163 const struct iomap_ops *ops);
164
165#if IS_ENABLED(CONFIG_DAX)
166int dax_read_lock(void);
167void dax_read_unlock(int id);
168#else
169static inline int dax_read_lock(void)
170{
171 return 0;
172}
173
174static inline void dax_read_unlock(int id)
175{
176}
177#endif /* CONFIG_DAX */
178bool dax_alive(struct dax_device *dax_dev);
179void *dax_get_private(struct dax_device *dax_dev);
180long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
181 void **kaddr, pfn_t *pfn);
182size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
183 size_t bytes, struct iov_iter *i);
184size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
185 size_t bytes, struct iov_iter *i);
186int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
187 size_t nr_pages);
188void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
189
190ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
191 const struct iomap_ops *ops);
192vm_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);
194vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
195 enum page_entry_size pe_size, pfn_t pfn);
196int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
197int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
198 pgoff_t index);
199static inline bool dax_mapping(struct address_space *mapping)
200{
201 return mapping->host && IS_DAX(mapping->host);
202}
203
204#ifdef CONFIG_DEV_DAX_HMEM_DEVICES
205void hmem_register_device(int target_nid, struct resource *r);
206#else
207static inline void hmem_register_device(int target_nid, struct resource *r)
208{
209}
210#endif
211
212#endif