blob: becaea5f4488880d54d7eb9a51716fba5d58d3f2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Matthew Wilcoxc94c2ac2015-09-08 14:58:40 -07002#ifndef _LINUX_DAX_H
3#define _LINUX_DAX_H
4
5#include <linux/fs.h>
6#include <linux/mm.h>
Jan Kara4f622932016-05-12 18:29:17 +02007#include <linux/radix-tree.h>
Matthew Wilcoxc94c2ac2015-09-08 14:58:40 -07008#include <asm/pgtable.h>
9
Matthew Wilcox27359fd2018-11-30 11:05:06 -050010typedef unsigned long dax_entry_t;
11
Christoph Hellwiga254e562016-09-19 11:24:49 +100012struct iomap_ops;
Dan Williams6568b082017-01-24 18:44:18 -080013struct dax_device;
14struct dax_operations {
15 /*
16 * direct_access: translate a device-relative
17 * logical-page-offset into an absolute physical pfn. Return the
18 * number of pages available for DAX at that pfn.
19 */
20 long (*direct_access)(struct dax_device *, pgoff_t, long,
21 void **, pfn_t *);
Dan Williams7bf7eac2019-05-16 13:26:29 -070022 /*
23 * Validate whether this device is usable as an fsdax backing
24 * device.
25 */
26 bool (*dax_supported)(struct dax_device *, struct block_device *, int,
27 sector_t, sector_t);
Dan Williams5d61e432017-06-27 13:06:22 -070028 /* copy_from_iter: required operation for fs-dax direct-i/o */
Dan Williams0aed55a2017-05-29 12:22:50 -070029 size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t,
30 struct iov_iter *);
Dan Williamsb3a9a0c2018-05-02 06:46:33 -070031 /* copy_to_iter: required operation for fs-dax direct-i/o */
32 size_t (*copy_to_iter)(struct dax_device *, pgoff_t, void *, size_t,
33 struct iov_iter *);
Dan Williams6568b082017-01-24 18:44:18 -080034};
Christoph Hellwiga254e562016-09-19 11:24:49 +100035
Dan Williams6e0c90d2017-06-26 21:28:41 -070036extern struct attribute_group dax_attribute_group;
37
Dan Williamsef510422017-05-08 10:55:27 -070038#if IS_ENABLED(CONFIG_DAX)
39struct dax_device *dax_get_by_host(const char *host);
Dan Williams976431b2018-03-29 17:22:13 -070040struct dax_device *alloc_dax(void *private, const char *host,
41 const struct dax_operations *ops);
Dan Williamsef510422017-05-08 10:55:27 -070042void put_dax(struct dax_device *dax_dev);
Dan Williams976431b2018-03-29 17:22:13 -070043void kill_dax(struct dax_device *dax_dev);
44void dax_write_cache(struct dax_device *dax_dev, bool wc);
45bool dax_write_cache_enabled(struct dax_device *dax_dev);
Dan Williamsef510422017-05-08 10:55:27 -070046#else
47static inline struct dax_device *dax_get_by_host(const char *host)
48{
49 return NULL;
50}
Dan Williams976431b2018-03-29 17:22:13 -070051static inline struct dax_device *alloc_dax(void *private, const char *host,
52 const struct dax_operations *ops)
53{
54 /*
55 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
56 * NULL is an error or expected.
57 */
58 return NULL;
59}
Dan Williamsef510422017-05-08 10:55:27 -070060static inline void put_dax(struct dax_device *dax_dev)
61{
62}
Dan Williams976431b2018-03-29 17:22:13 -070063static inline void kill_dax(struct dax_device *dax_dev)
64{
65}
66static inline void dax_write_cache(struct dax_device *dax_dev, bool wc)
67{
68}
69static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)
70{
71 return false;
72}
Dan Williamsef510422017-05-08 10:55:27 -070073#endif
74
Dan Williamsf44c7762018-03-07 15:26:44 -080075struct writeback_control;
Dan Williamsf5705aa8c2017-05-13 16:31:05 -070076int bdev_dax_pgoff(struct block_device *, sector_t, size_t, pgoff_t *pgoff);
77#if IS_ENABLED(CONFIG_FS_DAX)
Dave Jiang80660f22018-05-30 13:03:46 -070078bool __bdev_dax_supported(struct block_device *bdev, int blocksize);
79static inline bool bdev_dax_supported(struct block_device *bdev, int blocksize)
Dan Williamsf5705aa8c2017-05-13 16:31:05 -070080{
Darrick J. Wongba23cba2018-05-30 13:03:45 -070081 return __bdev_dax_supported(bdev, blocksize);
Dan Williamsf5705aa8c2017-05-13 16:31:05 -070082}
83
Dan Williams7bf7eac2019-05-16 13:26:29 -070084bool __generic_fsdax_supported(struct dax_device *dax_dev,
85 struct block_device *bdev, int blocksize, sector_t start,
86 sector_t sectors);
87static inline bool generic_fsdax_supported(struct dax_device *dax_dev,
88 struct block_device *bdev, int blocksize, sector_t start,
89 sector_t sectors)
90{
91 return __generic_fsdax_supported(dax_dev, bdev, blocksize, start,
92 sectors);
93}
94
Dan Williamsf5705aa8c2017-05-13 16:31:05 -070095static inline struct dax_device *fs_dax_get_by_host(const char *host)
96{
97 return dax_get_by_host(host);
98}
99
100static inline void fs_put_dax(struct dax_device *dax_dev)
101{
102 put_dax(dax_dev);
103}
104
Dan Williams78f35472017-08-30 09:16:38 -0700105struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev);
Dan Williamsf44c7762018-03-07 15:26:44 -0800106int dax_writeback_mapping_range(struct address_space *mapping,
107 struct block_device *bdev, struct writeback_control *wbc);
Dan Williams5fac7402018-03-09 17:44:31 -0800108
109struct page *dax_layout_busy_page(struct address_space *mapping);
Matthew Wilcox27359fd2018-11-30 11:05:06 -0500110dax_entry_t dax_lock_page(struct page *page);
111void dax_unlock_page(struct page *page, dax_entry_t cookie);
Dan Williamsf5705aa8c2017-05-13 16:31:05 -0700112#else
Dave Jiang80660f22018-05-30 13:03:46 -0700113static inline bool bdev_dax_supported(struct block_device *bdev,
Darrick J. Wongba23cba2018-05-30 13:03:45 -0700114 int blocksize)
Dan Williamsf5705aa8c2017-05-13 16:31:05 -0700115{
Dave Jiang80660f22018-05-30 13:03:46 -0700116 return false;
Dan Williamsf5705aa8c2017-05-13 16:31:05 -0700117}
118
Dan Williams7bf7eac2019-05-16 13:26:29 -0700119static inline bool generic_fsdax_supported(struct dax_device *dax_dev,
120 struct block_device *bdev, int blocksize, sector_t start,
121 sector_t sectors)
122{
123 return false;
124}
125
Dan Williamsf5705aa8c2017-05-13 16:31:05 -0700126static inline struct dax_device *fs_dax_get_by_host(const char *host)
127{
128 return NULL;
129}
130
131static inline void fs_put_dax(struct dax_device *dax_dev)
132{
133}
Dan Williams78f35472017-08-30 09:16:38 -0700134
135static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev)
136{
137 return NULL;
138}
Dan Williamsf44c7762018-03-07 15:26:44 -0800139
Dan Williams5fac7402018-03-09 17:44:31 -0800140static inline struct page *dax_layout_busy_page(struct address_space *mapping)
141{
142 return NULL;
143}
144
Dan Williamsf44c7762018-03-07 15:26:44 -0800145static inline int dax_writeback_mapping_range(struct address_space *mapping,
146 struct block_device *bdev, struct writeback_control *wbc)
147{
148 return -EOPNOTSUPP;
149}
Dan Williamsc2a7d2a2018-07-13 21:50:16 -0700150
Matthew Wilcox27359fd2018-11-30 11:05:06 -0500151static inline dax_entry_t dax_lock_page(struct page *page)
Dan Williamsc2a7d2a2018-07-13 21:50:16 -0700152{
153 if (IS_DAX(page->mapping->host))
Matthew Wilcox27359fd2018-11-30 11:05:06 -0500154 return ~0UL;
155 return 0;
Dan Williamsc2a7d2a2018-07-13 21:50:16 -0700156}
157
Matthew Wilcox27359fd2018-11-30 11:05:06 -0500158static inline void dax_unlock_page(struct page *page, dax_entry_t cookie)
Dan Williamsc2a7d2a2018-07-13 21:50:16 -0700159{
160}
Dan Williamsf5705aa8c2017-05-13 16:31:05 -0700161#endif
162
Dan Williams7b6be842017-04-11 09:49:49 -0700163int dax_read_lock(void);
164void dax_read_unlock(int id);
Dan Williamsc1d6e822017-01-24 23:02:09 -0800165bool dax_alive(struct dax_device *dax_dev);
Dan Williamsc1d6e822017-01-24 23:02:09 -0800166void *dax_get_private(struct dax_device *dax_dev);
Dan Williamsb0686262017-01-26 20:37:35 -0800167long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
168 void **kaddr, pfn_t *pfn);
Dan Williams7bf7eac2019-05-16 13:26:29 -0700169bool dax_supported(struct dax_device *dax_dev, struct block_device *bdev,
170 int blocksize, sector_t start, sector_t len);
Dan Williams7e026c82017-05-29 12:57:56 -0700171size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
172 size_t bytes, struct iov_iter *i);
Dan Williamsb3a9a0c2018-05-02 06:46:33 -0700173size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
174 size_t bytes, struct iov_iter *i);
Mikulas Patockac3ca0152017-08-31 21:47:43 -0400175void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
Dan Williams7b6be842017-04-11 09:49:49 -0700176
Ross Zwisler11c59c92016-11-08 11:32:46 +1100177ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
Christoph Hellwig8ff6daa2017-01-27 23:20:26 -0800178 const struct iomap_ops *ops);
Souptick Joarderf77bc3a2018-06-27 23:26:17 -0700179vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
Jan Karac0b24622018-01-07 16:38:43 -0500180 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
Souptick Joarderab77dab2018-06-07 17:04:29 -0700181vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
182 enum page_entry_size pe_size, pfn_t pfn);
Jan Karaac401cc2016-05-12 18:29:18 +0200183int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
Jan Karac6dcf522016-08-10 17:22:44 +0200184int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
185 pgoff_t index);
Dan Williamsd1a5f2b42016-01-28 20:25:31 -0800186
187#ifdef CONFIG_FS_DAX
Dan Williamscccbce62017-01-27 13:31:42 -0800188int __dax_zero_page_range(struct block_device *bdev,
189 struct dax_device *dax_dev, sector_t sector,
Christoph Hellwig679c8bd2016-05-09 10:47:04 +0200190 unsigned int offset, unsigned int length);
Dan Williamsd1a5f2b42016-01-28 20:25:31 -0800191#else
Christoph Hellwig679c8bd2016-05-09 10:47:04 +0200192static inline int __dax_zero_page_range(struct block_device *bdev,
Dan Williamscccbce62017-01-27 13:31:42 -0800193 struct dax_device *dax_dev, sector_t sector,
194 unsigned int offset, unsigned int length)
Christoph Hellwig679c8bd2016-05-09 10:47:04 +0200195{
196 return -ENXIO;
197}
Dan Williamsd1a5f2b42016-01-28 20:25:31 -0800198#endif
199
Ross Zwislerf9fe48b2016-01-22 15:10:40 -0800200static inline bool dax_mapping(struct address_space *mapping)
201{
202 return mapping->host && IS_DAX(mapping->host);
203}
Ross Zwisler7f6d5b52016-02-26 15:19:55 -0800204
Matthew Wilcoxc94c2ac2015-09-08 14:58:40 -0700205#endif