Commit | Line | Data |
---|---|---|
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 |
9 | typedef unsigned long dax_entry_t; |
10 | ||
fb08a190 CH |
11 | struct dax_device; |
12 | struct gendisk; | |
a254e568 | 13 | struct iomap_ops; |
c6f40468 | 14 | struct iomap_iter; |
4f3b4f16 | 15 | struct iomap; |
fb08a190 | 16 | |
6568b08b DW |
17 | struct 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 | |
f5705aa8 | 41 | #if IS_ENABLED(CONFIG_DAX) |
30c6828a | 42 | struct dax_device *alloc_dax(void *private, const struct dax_operations *ops); |
f5705aa8 | 43 | void put_dax(struct dax_device *dax_dev); |
976431b0 DW |
44 | void kill_dax(struct dax_device *dax_dev); |
45 | void dax_write_cache(struct dax_device *dax_dev, bool wc); | |
46 | bool dax_write_cache_enabled(struct dax_device *dax_dev); | |
fd1d00ec CH |
47 | bool dax_synchronous(struct dax_device *dax_dev); |
48 | void set_dax_synchronous(struct dax_device *dax_dev); | |
32de1484 PG |
49 | /* |
50 | * Check if given mapping is supported by the file / underlying device. | |
51 | */ | |
52 | static inline bool daxdev_mapping_supported(struct vm_area_struct *vma, | |
53 | struct dax_device *dax_dev) | |
54 | { | |
55 | if (!(vma->vm_flags & VM_SYNC)) | |
56 | return true; | |
57 | if (!IS_DAX(file_inode(vma->vm_file))) | |
58 | return false; | |
59 | return dax_synchronous(dax_dev); | |
60 | } | |
f5705aa8 | 61 | #else |
fb08a190 | 62 | static inline struct dax_device *alloc_dax(void *private, |
30c6828a | 63 | const struct dax_operations *ops) |
976431b0 DW |
64 | { |
65 | /* | |
66 | * Callers should check IS_ENABLED(CONFIG_DAX) to know if this | |
67 | * NULL is an error or expected. | |
68 | */ | |
69 | return NULL; | |
70 | } | |
f5705aa8 DW |
71 | static inline void put_dax(struct dax_device *dax_dev) |
72 | { | |
73 | } | |
976431b0 DW |
74 | static inline void kill_dax(struct dax_device *dax_dev) |
75 | { | |
76 | } | |
77 | static inline void dax_write_cache(struct dax_device *dax_dev, bool wc) | |
78 | { | |
79 | } | |
80 | static inline bool dax_write_cache_enabled(struct dax_device *dax_dev) | |
81 | { | |
82 | return false; | |
83 | } | |
fefc1d97 PG |
84 | static inline bool dax_synchronous(struct dax_device *dax_dev) |
85 | { | |
86 | return true; | |
87 | } | |
88 | static inline void set_dax_synchronous(struct dax_device *dax_dev) | |
89 | { | |
90 | } | |
32de1484 PG |
91 | static inline bool daxdev_mapping_supported(struct vm_area_struct *vma, |
92 | struct dax_device *dax_dev) | |
93 | { | |
94 | return !(vma->vm_flags & VM_SYNC); | |
95 | } | |
f5705aa8 DW |
96 | #endif |
97 | ||
f44c7763 | 98 | struct writeback_control; |
2ede8923 | 99 | #if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX) |
fb08a190 CH |
100 | int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk); |
101 | void dax_remove_host(struct gendisk *disk); | |
2ede8923 CH |
102 | struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev, |
103 | u64 *start_off); | |
f5705aa8 DW |
104 | static inline void fs_put_dax(struct dax_device *dax_dev) |
105 | { | |
106 | put_dax(dax_dev); | |
107 | } | |
ef510424 | 108 | #else |
fb08a190 CH |
109 | static inline int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk) |
110 | { | |
111 | return 0; | |
112 | } | |
113 | static inline void dax_remove_host(struct gendisk *disk) | |
114 | { | |
115 | } | |
cd913c76 CH |
116 | static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev, |
117 | u64 *start_off) | |
78f35473 DW |
118 | { |
119 | return NULL; | |
120 | } | |
2ede8923 CH |
121 | static inline void fs_put_dax(struct dax_device *dax_dev) |
122 | { | |
123 | } | |
124 | #endif /* CONFIG_BLOCK && CONFIG_FS_DAX */ | |
f44c7763 | 125 | |
2ede8923 CH |
126 | #if IS_ENABLED(CONFIG_FS_DAX) |
127 | int dax_writeback_mapping_range(struct address_space *mapping, | |
128 | struct dax_device *dax_dev, struct writeback_control *wbc); | |
129 | ||
130 | struct page *dax_layout_busy_page(struct address_space *mapping); | |
131 | struct page *dax_layout_busy_page_range(struct address_space *mapping, loff_t start, loff_t end); | |
132 | dax_entry_t dax_lock_page(struct page *page); | |
133 | void dax_unlock_page(struct page *page, dax_entry_t cookie); | |
134 | #else | |
5fac7408 DW |
135 | static inline struct page *dax_layout_busy_page(struct address_space *mapping) |
136 | { | |
137 | return NULL; | |
138 | } | |
139 | ||
6bbdd563 VG |
140 | static inline struct page *dax_layout_busy_page_range(struct address_space *mapping, pgoff_t start, pgoff_t nr_pages) |
141 | { | |
142 | return NULL; | |
143 | } | |
144 | ||
f44c7763 | 145 | static inline int dax_writeback_mapping_range(struct address_space *mapping, |
3f666c56 | 146 | struct dax_device *dax_dev, struct writeback_control *wbc) |
f44c7763 DW |
147 | { |
148 | return -EOPNOTSUPP; | |
149 | } | |
c2a7d2a1 | 150 | |
27359fd6 | 151 | static inline dax_entry_t dax_lock_page(struct page *page) |
c2a7d2a1 DW |
152 | { |
153 | if (IS_DAX(page->mapping->host)) | |
27359fd6 MW |
154 | return ~0UL; |
155 | return 0; | |
c2a7d2a1 DW |
156 | } |
157 | ||
27359fd6 | 158 | static inline void dax_unlock_page(struct page *page, dax_entry_t cookie) |
c2a7d2a1 DW |
159 | { |
160 | } | |
ef510424 DW |
161 | #endif |
162 | ||
c6f40468 CH |
163 | int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, |
164 | const struct iomap_ops *ops); | |
165 | int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, | |
166 | const struct iomap_ops *ops); | |
167 | ||
e2ec5128 | 168 | #if IS_ENABLED(CONFIG_DAX) |
7b6be844 DW |
169 | int dax_read_lock(void); |
170 | void dax_read_unlock(int id); | |
e2ec5128 JK |
171 | #else |
172 | static inline int dax_read_lock(void) | |
173 | { | |
174 | return 0; | |
175 | } | |
176 | ||
177 | static inline void dax_read_unlock(int id) | |
178 | { | |
179 | } | |
180 | #endif /* CONFIG_DAX */ | |
c1d6e828 | 181 | bool dax_alive(struct dax_device *dax_dev); |
c1d6e828 | 182 | void *dax_get_private(struct dax_device *dax_dev); |
b0686260 DW |
183 | long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages, |
184 | void **kaddr, pfn_t *pfn); | |
7e026c8c DW |
185 | size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, |
186 | size_t bytes, struct iov_iter *i); | |
b3a9a0c3 DW |
187 | size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, |
188 | size_t bytes, struct iov_iter *i); | |
f605a263 VG |
189 | int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, |
190 | size_t nr_pages); | |
c3ca015f | 191 | void dax_flush(struct dax_device *dax_dev, void *addr, size_t size); |
7b6be844 | 192 | |
11c59c92 | 193 | ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter, |
8ff6daa1 | 194 | const struct iomap_ops *ops); |
f77bc3a8 | 195 | vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size, |
c0b24625 | 196 | pfn_t *pfnp, int *errp, const struct iomap_ops *ops); |
ab77dab4 SJ |
197 | vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, |
198 | enum page_entry_size pe_size, pfn_t pfn); | |
ac401cc7 | 199 | int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index); |
c6dcf52c JK |
200 | int dax_invalidate_mapping_entry_sync(struct address_space *mapping, |
201 | pgoff_t index); | |
f9fe48be RZ |
202 | static inline bool dax_mapping(struct address_space *mapping) |
203 | { | |
204 | return mapping->host && IS_DAX(mapping->host); | |
205 | } | |
7f6d5b52 | 206 | |
c01044cc DW |
207 | #ifdef CONFIG_DEV_DAX_HMEM_DEVICES |
208 | void hmem_register_device(int target_nid, struct resource *r); | |
209 | #else | |
210 | static inline void hmem_register_device(int target_nid, struct resource *r) | |
211 | { | |
212 | } | |
213 | #endif | |
214 | ||
c94c2acf | 215 | #endif |