]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blame - include/linux/dax.h
Merge tag 'powerpc-5.13-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[mirror_ubuntu-kernels.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
DW
43#if IS_ENABLED(CONFIG_DAX)
44struct dax_device *dax_get_by_host(const char *host);
976431b0 45struct dax_device *alloc_dax(void *private, const char *host,
fefc1d97 46 const struct dax_operations *ops, unsigned long flags);
f5705aa8 47void put_dax(struct dax_device *dax_dev);
976431b0
DW
48void kill_dax(struct dax_device *dax_dev);
49void dax_write_cache(struct dax_device *dax_dev, bool wc);
50bool dax_write_cache_enabled(struct dax_device *dax_dev);
fefc1d97
PG
51bool __dax_synchronous(struct dax_device *dax_dev);
52static inline bool dax_synchronous(struct dax_device *dax_dev)
53{
54 return __dax_synchronous(dax_dev);
55}
56void __set_dax_synchronous(struct dax_device *dax_dev);
57static inline void set_dax_synchronous(struct dax_device *dax_dev)
58{
59 __set_dax_synchronous(dax_dev);
60}
88b67edd
JK
61bool dax_supported(struct dax_device *dax_dev, struct block_device *bdev,
62 int blocksize, sector_t start, sector_t len);
32de1484
PG
63/*
64 * Check if given mapping is supported by the file / underlying device.
65 */
66static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
67 struct dax_device *dax_dev)
68{
69 if (!(vma->vm_flags & VM_SYNC))
70 return true;
71 if (!IS_DAX(file_inode(vma->vm_file)))
72 return false;
73 return dax_synchronous(dax_dev);
74}
f5705aa8
DW
75#else
76static inline struct dax_device *dax_get_by_host(const char *host)
77{
78 return NULL;
79}
976431b0 80static inline struct dax_device *alloc_dax(void *private, const char *host,
fefc1d97 81 const struct dax_operations *ops, unsigned long flags)
976431b0
DW
82{
83 /*
84 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
85 * NULL is an error or expected.
86 */
87 return NULL;
88}
f5705aa8
DW
89static inline void put_dax(struct dax_device *dax_dev)
90{
91}
976431b0
DW
92static inline void kill_dax(struct dax_device *dax_dev)
93{
94}
95static inline void dax_write_cache(struct dax_device *dax_dev, bool wc)
96{
97}
98static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)
99{
100 return false;
101}
fefc1d97
PG
102static inline bool dax_synchronous(struct dax_device *dax_dev)
103{
104 return true;
105}
106static inline void set_dax_synchronous(struct dax_device *dax_dev)
107{
108}
88b67edd
JK
109static inline bool dax_supported(struct dax_device *dax_dev,
110 struct block_device *bdev, int blocksize, sector_t start,
111 sector_t len)
112{
113 return false;
114}
32de1484
PG
115static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
116 struct dax_device *dax_dev)
117{
118 return !(vma->vm_flags & VM_SYNC);
119}
f5705aa8
DW
120#endif
121
f44c7763 122struct writeback_control;
ef510424
DW
123int bdev_dax_pgoff(struct block_device *, sector_t, size_t, pgoff_t *pgoff);
124#if IS_ENABLED(CONFIG_FS_DAX)
80660f20
DJ
125bool __bdev_dax_supported(struct block_device *bdev, int blocksize);
126static inline bool bdev_dax_supported(struct block_device *bdev, int blocksize)
ef510424 127{
ba23cba9 128 return __bdev_dax_supported(bdev, blocksize);
ef510424 129}
f5705aa8 130
7bf7eac8
DW
131bool __generic_fsdax_supported(struct dax_device *dax_dev,
132 struct block_device *bdev, int blocksize, sector_t start,
133 sector_t sectors);
134static inline bool generic_fsdax_supported(struct dax_device *dax_dev,
135 struct block_device *bdev, int blocksize, sector_t start,
136 sector_t sectors)
137{
138 return __generic_fsdax_supported(dax_dev, bdev, blocksize, start,
139 sectors);
140}
141
f5705aa8
DW
142static inline void fs_put_dax(struct dax_device *dax_dev)
143{
144 put_dax(dax_dev);
145}
146
78f35473 147struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev);
f44c7763 148int dax_writeback_mapping_range(struct address_space *mapping,
3f666c56 149 struct dax_device *dax_dev, struct writeback_control *wbc);
5fac7408
DW
150
151struct page *dax_layout_busy_page(struct address_space *mapping);
6bbdd563 152struct page *dax_layout_busy_page_range(struct address_space *mapping, loff_t start, loff_t end);
27359fd6
MW
153dax_entry_t dax_lock_page(struct page *page);
154void dax_unlock_page(struct page *page, dax_entry_t cookie);
ef510424 155#else
80660f20 156static inline bool bdev_dax_supported(struct block_device *bdev,
ba23cba9 157 int blocksize)
ef510424 158{
80660f20 159 return false;
ef510424 160}
ef510424 161
7bf7eac8
DW
162static inline bool generic_fsdax_supported(struct dax_device *dax_dev,
163 struct block_device *bdev, int blocksize, sector_t start,
164 sector_t sectors)
165{
166 return false;
167}
168
f5705aa8 169static inline void fs_put_dax(struct dax_device *dax_dev)
ef510424
DW
170{
171}
78f35473
DW
172
173static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev)
174{
175 return NULL;
176}
f44c7763 177
5fac7408
DW
178static inline struct page *dax_layout_busy_page(struct address_space *mapping)
179{
180 return NULL;
181}
182
6bbdd563
VG
183static inline struct page *dax_layout_busy_page_range(struct address_space *mapping, pgoff_t start, pgoff_t nr_pages)
184{
185 return NULL;
186}
187
f44c7763 188static inline int dax_writeback_mapping_range(struct address_space *mapping,
3f666c56 189 struct dax_device *dax_dev, struct writeback_control *wbc)
f44c7763
DW
190{
191 return -EOPNOTSUPP;
192}
c2a7d2a1 193
27359fd6 194static inline dax_entry_t dax_lock_page(struct page *page)
c2a7d2a1
DW
195{
196 if (IS_DAX(page->mapping->host))
27359fd6
MW
197 return ~0UL;
198 return 0;
c2a7d2a1
DW
199}
200
27359fd6 201static inline void dax_unlock_page(struct page *page, dax_entry_t cookie)
c2a7d2a1
DW
202{
203}
ef510424
DW
204#endif
205
e2ec5128 206#if IS_ENABLED(CONFIG_DAX)
7b6be844
DW
207int dax_read_lock(void);
208void dax_read_unlock(int id);
e2ec5128
JK
209#else
210static inline int dax_read_lock(void)
211{
212 return 0;
213}
214
215static inline void dax_read_unlock(int id)
216{
217}
218#endif /* CONFIG_DAX */
c1d6e828 219bool dax_alive(struct dax_device *dax_dev);
c1d6e828 220void *dax_get_private(struct dax_device *dax_dev);
b0686260
DW
221long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
222 void **kaddr, pfn_t *pfn);
7e026c8c
DW
223size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
224 size_t bytes, struct iov_iter *i);
b3a9a0c3
DW
225size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
226 size_t bytes, struct iov_iter *i);
f605a263
VG
227int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
228 size_t nr_pages);
c3ca015f 229void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
7b6be844 230
11c59c92 231ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
8ff6daa1 232 const struct iomap_ops *ops);
f77bc3a8 233vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
c0b24625 234 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
ab77dab4
SJ
235vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
236 enum page_entry_size pe_size, pfn_t pfn);
ac401cc7 237int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
c6dcf52c
JK
238int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
239 pgoff_t index);
81ee8e52 240s64 dax_iomap_zero(loff_t pos, u64 length, struct iomap *iomap);
f9fe48be
RZ
241static inline bool dax_mapping(struct address_space *mapping)
242{
243 return mapping->host && IS_DAX(mapping->host);
244}
7f6d5b52 245
c01044cc
DW
246#ifdef CONFIG_DEV_DAX_HMEM_DEVICES
247void hmem_register_device(int target_nid, struct resource *r);
248#else
249static inline void hmem_register_device(int target_nid, struct resource *r)
250{
251}
252#endif
253
c94c2acf 254#endif