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
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
27359fd6
MW
9typedef unsigned long dax_entry_t;
10
fb08a190
CH
11struct dax_device;
12struct gendisk;
a254e568 13struct iomap_ops;
c6f40468 14struct iomap_iter;
4f3b4f16 15struct iomap;
fb08a190 16
6568b08b
DW
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);
f605a263
VG
31 /* zero_page_range: required operation. Zero page range */
32 int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
6568b08b 33};
a254e568 34
f5705aa8 35#if IS_ENABLED(CONFIG_DAX)
30c6828a 36struct dax_device *alloc_dax(void *private, const struct dax_operations *ops);
f5705aa8 37void put_dax(struct dax_device *dax_dev);
976431b0
DW
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);
fd1d00ec
CH
41bool dax_synchronous(struct dax_device *dax_dev);
42void set_dax_synchronous(struct dax_device *dax_dev);
32de1484
PG
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}
f5705aa8 55#else
fb08a190 56static inline struct dax_device *alloc_dax(void *private,
30c6828a 57 const struct dax_operations *ops)
976431b0
DW
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}
f5705aa8
DW
65static inline void put_dax(struct dax_device *dax_dev)
66{
67}
976431b0
DW
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}
fefc1d97
PG
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}
32de1484
PG
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}
f5705aa8
DW
90#endif
91
7ac5360c
CH
92void set_dax_nocache(struct dax_device *dax_dev);
93void set_dax_nomc(struct dax_device *dax_dev);
94
f44c7763 95struct writeback_control;
2ede8923 96#if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX)
fb08a190
CH
97int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk);
98void dax_remove_host(struct gendisk *disk);
2ede8923
CH
99struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev,
100 u64 *start_off);
f5705aa8
DW
101static inline void fs_put_dax(struct dax_device *dax_dev)
102{
103 put_dax(dax_dev);
104}
ef510424 105#else
fb08a190
CH
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}
cd913c76
CH
113static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev,
114 u64 *start_off)
78f35473
DW
115{
116 return NULL;
117}
2ede8923
CH
118static inline void fs_put_dax(struct dax_device *dax_dev)
119{
120}
121#endif /* CONFIG_BLOCK && CONFIG_FS_DAX */
f44c7763 122
2ede8923
CH
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
5fac7408
DW
132static inline struct page *dax_layout_busy_page(struct address_space *mapping)
133{
134 return NULL;
135}
136
6bbdd563
VG
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
f44c7763 142static inline int dax_writeback_mapping_range(struct address_space *mapping,
3f666c56 143 struct dax_device *dax_dev, struct writeback_control *wbc)
f44c7763
DW
144{
145 return -EOPNOTSUPP;
146}
c2a7d2a1 147
27359fd6 148static inline dax_entry_t dax_lock_page(struct page *page)
c2a7d2a1
DW
149{
150 if (IS_DAX(page->mapping->host))
27359fd6
MW
151 return ~0UL;
152 return 0;
c2a7d2a1
DW
153}
154
27359fd6 155static inline void dax_unlock_page(struct page *page, dax_entry_t cookie)
c2a7d2a1
DW
156{
157}
ef510424
DW
158#endif
159
c6f40468
CH
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
e2ec5128 165#if IS_ENABLED(CONFIG_DAX)
7b6be844
DW
166int dax_read_lock(void);
167void dax_read_unlock(int id);
e2ec5128
JK
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 */
c1d6e828 178bool dax_alive(struct dax_device *dax_dev);
c1d6e828 179void *dax_get_private(struct dax_device *dax_dev);
b0686260
DW
180long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
181 void **kaddr, pfn_t *pfn);
7e026c8c
DW
182size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
183 size_t bytes, struct iov_iter *i);
b3a9a0c3
DW
184size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
185 size_t bytes, struct iov_iter *i);
f605a263
VG
186int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
187 size_t nr_pages);
c3ca015f 188void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
7b6be844 189
11c59c92 190ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
8ff6daa1 191 const struct iomap_ops *ops);
f77bc3a8 192vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
c0b24625 193 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
ab77dab4
SJ
194vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
195 enum page_entry_size pe_size, pfn_t pfn);
ac401cc7 196int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
c6dcf52c
JK
197int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
198 pgoff_t index);
f9fe48be
RZ
199static inline bool dax_mapping(struct address_space *mapping)
200{
201 return mapping->host && IS_DAX(mapping->host);
202}
7f6d5b52 203
c01044cc
DW
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
c94c2acf 212#endif