Merge tag '5.15-rc-cifs-part2' of git://git.samba.org/sfrench/cifs-2.6
[linux-block.git] / include / linux / dax.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
c94c2acf
MW
2#ifndef _LINUX_DAX_H
3#define _LINUX_DAX_H
4
5#include <linux/fs.h>
6#include <linux/mm.h>
4f622938 7#include <linux/radix-tree.h>
c94c2acf 8
fefc1d97
PG
9/* Flag for synchronous flush */
10#define DAXDEV_F_SYNC (1UL << 0)
11
27359fd6
MW
12typedef unsigned long dax_entry_t;
13
a254e568 14struct iomap_ops;
4f3b4f16 15struct iomap;
6568b08b
DW
16struct dax_device;
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 *);
7bf7eac8
DW
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);
5d61e43b 31 /* copy_from_iter: required operation for fs-dax direct-i/o */
0aed55af
DW
32 size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t,
33 struct iov_iter *);
b3a9a0c3
DW
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,
36 struct iov_iter *);
f605a263
VG
37 /* zero_page_range: required operation. Zero page range */
38 int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
6568b08b 39};
a254e568 40
6e0c90d6
DW
41extern struct attribute_group dax_attribute_group;
42
f5705aa8 43#if IS_ENABLED(CONFIG_DAX)
976431b0 44struct dax_device *alloc_dax(void *private, const char *host,
fefc1d97 45 const struct dax_operations *ops, unsigned long flags);
f5705aa8 46void put_dax(struct dax_device *dax_dev);
976431b0
DW
47void kill_dax(struct dax_device *dax_dev);
48void dax_write_cache(struct dax_device *dax_dev, bool wc);
49bool dax_write_cache_enabled(struct dax_device *dax_dev);
fefc1d97
PG
50bool __dax_synchronous(struct dax_device *dax_dev);
51static inline bool dax_synchronous(struct dax_device *dax_dev)
52{
53 return __dax_synchronous(dax_dev);
54}
55void __set_dax_synchronous(struct dax_device *dax_dev);
56static inline void set_dax_synchronous(struct dax_device *dax_dev)
57{
58 __set_dax_synchronous(dax_dev);
59}
32de1484
PG
60/*
61 * Check if given mapping is supported by the file / underlying device.
62 */
63static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
64 struct dax_device *dax_dev)
65{
66 if (!(vma->vm_flags & VM_SYNC))
67 return true;
68 if (!IS_DAX(file_inode(vma->vm_file)))
69 return false;
70 return dax_synchronous(dax_dev);
71}
f5705aa8 72#else
976431b0 73static inline struct dax_device *alloc_dax(void *private, const char *host,
fefc1d97 74 const struct dax_operations *ops, unsigned long flags)
976431b0
DW
75{
76 /*
77 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
78 * NULL is an error or expected.
79 */
80 return NULL;
81}
f5705aa8
DW
82static inline void put_dax(struct dax_device *dax_dev)
83{
84}
976431b0
DW
85static inline void kill_dax(struct dax_device *dax_dev)
86{
87}
88static inline void dax_write_cache(struct dax_device *dax_dev, bool wc)
89{
90}
91static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)
92{
93 return false;
94}
fefc1d97
PG
95static inline bool dax_synchronous(struct dax_device *dax_dev)
96{
97 return true;
98}
99static inline void set_dax_synchronous(struct dax_device *dax_dev)
100{
101}
32de1484
PG
102static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
103 struct dax_device *dax_dev)
104{
105 return !(vma->vm_flags & VM_SYNC);
106}
f5705aa8
DW
107#endif
108
f44c7763 109struct writeback_control;
ef510424
DW
110int bdev_dax_pgoff(struct block_device *, sector_t, size_t, pgoff_t *pgoff);
111#if IS_ENABLED(CONFIG_FS_DAX)
cd93a2a4 112bool generic_fsdax_supported(struct dax_device *dax_dev,
7bf7eac8
DW
113 struct block_device *bdev, int blocksize, sector_t start,
114 sector_t sectors);
7bf7eac8 115
60b8340f
CH
116bool dax_supported(struct dax_device *dax_dev, struct block_device *bdev,
117 int blocksize, sector_t start, sector_t len);
118
f5705aa8
DW
119static inline void fs_put_dax(struct dax_device *dax_dev)
120{
121 put_dax(dax_dev);
122}
123
78f35473 124struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev);
f44c7763 125int dax_writeback_mapping_range(struct address_space *mapping,
3f666c56 126 struct dax_device *dax_dev, struct writeback_control *wbc);
5fac7408
DW
127
128struct page *dax_layout_busy_page(struct address_space *mapping);
6bbdd563 129struct page *dax_layout_busy_page_range(struct address_space *mapping, loff_t start, loff_t end);
27359fd6
MW
130dax_entry_t dax_lock_page(struct page *page);
131void dax_unlock_page(struct page *page, dax_entry_t cookie);
ef510424 132#else
cd93a2a4 133#define generic_fsdax_supported NULL
7bf7eac8 134
60b8340f
CH
135static inline bool dax_supported(struct dax_device *dax_dev,
136 struct block_device *bdev, int blocksize, sector_t start,
137 sector_t len)
138{
139 return false;
140}
141
f5705aa8 142static inline void fs_put_dax(struct dax_device *dax_dev)
ef510424
DW
143{
144}
78f35473
DW
145
146static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev)
147{
148 return NULL;
149}
f44c7763 150
5fac7408
DW
151static inline struct page *dax_layout_busy_page(struct address_space *mapping)
152{
153 return NULL;
154}
155
6bbdd563
VG
156static inline struct page *dax_layout_busy_page_range(struct address_space *mapping, pgoff_t start, pgoff_t nr_pages)
157{
158 return NULL;
159}
160
f44c7763 161static inline int dax_writeback_mapping_range(struct address_space *mapping,
3f666c56 162 struct dax_device *dax_dev, struct writeback_control *wbc)
f44c7763
DW
163{
164 return -EOPNOTSUPP;
165}
c2a7d2a1 166
27359fd6 167static inline dax_entry_t dax_lock_page(struct page *page)
c2a7d2a1
DW
168{
169 if (IS_DAX(page->mapping->host))
27359fd6
MW
170 return ~0UL;
171 return 0;
c2a7d2a1
DW
172}
173
27359fd6 174static inline void dax_unlock_page(struct page *page, dax_entry_t cookie)
c2a7d2a1
DW
175{
176}
ef510424
DW
177#endif
178
e2ec5128 179#if IS_ENABLED(CONFIG_DAX)
7b6be844
DW
180int dax_read_lock(void);
181void dax_read_unlock(int id);
e2ec5128
JK
182#else
183static inline int dax_read_lock(void)
184{
185 return 0;
186}
187
188static inline void dax_read_unlock(int id)
189{
190}
191#endif /* CONFIG_DAX */
c1d6e828 192bool dax_alive(struct dax_device *dax_dev);
c1d6e828 193void *dax_get_private(struct dax_device *dax_dev);
b0686260
DW
194long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
195 void **kaddr, pfn_t *pfn);
7e026c8c
DW
196size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
197 size_t bytes, struct iov_iter *i);
b3a9a0c3
DW
198size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
199 size_t bytes, struct iov_iter *i);
f605a263
VG
200int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
201 size_t nr_pages);
c3ca015f 202void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
7b6be844 203
11c59c92 204ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
8ff6daa1 205 const struct iomap_ops *ops);
f77bc3a8 206vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
c0b24625 207 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
ab77dab4
SJ
208vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
209 enum page_entry_size pe_size, pfn_t pfn);
ac401cc7 210int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
c6dcf52c
JK
211int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
212 pgoff_t index);
81ee8e52 213s64 dax_iomap_zero(loff_t pos, u64 length, struct iomap *iomap);
f9fe48be
RZ
214static inline bool dax_mapping(struct address_space *mapping)
215{
216 return mapping->host && IS_DAX(mapping->host);
217}
7f6d5b52 218
c01044cc
DW
219#ifdef CONFIG_DEV_DAX_HMEM_DEVICES
220void hmem_register_device(int target_nid, struct resource *r);
221#else
222static inline void hmem_register_device(int target_nid, struct resource *r)
223{
224}
225#endif
226
c94c2acf 227#endif