blob: 450b28db95331ffbe19963c804391d7249cfb2c3 [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
Christoph Hellwiga254e562016-09-19 11:24:49 +100010struct iomap_ops;
Dan Williams6568b082017-01-24 18:44:18 -080011struct dax_device;
12struct dax_operations {
13 /*
14 * direct_access: translate a device-relative
15 * logical-page-offset into an absolute physical pfn. Return the
16 * number of pages available for DAX at that pfn.
17 */
18 long (*direct_access)(struct dax_device *, pgoff_t, long,
19 void **, pfn_t *);
Dan Williams5d61e432017-06-27 13:06:22 -070020 /* copy_from_iter: required operation for fs-dax direct-i/o */
Dan Williams0aed55a2017-05-29 12:22:50 -070021 size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t,
22 struct iov_iter *);
Dan Williamsb3a9a0c2018-05-02 06:46:33 -070023 /* copy_to_iter: required operation for fs-dax direct-i/o */
24 size_t (*copy_to_iter)(struct dax_device *, pgoff_t, void *, size_t,
25 struct iov_iter *);
Dan Williams6568b082017-01-24 18:44:18 -080026};
Christoph Hellwiga254e562016-09-19 11:24:49 +100027
Dan Williams6e0c90d2017-06-26 21:28:41 -070028extern struct attribute_group dax_attribute_group;
29
Dan Williamsef5104242017-05-08 10:55:27 -070030#if IS_ENABLED(CONFIG_DAX)
31struct dax_device *dax_get_by_host(const char *host);
Dan Williams976431b2018-03-29 17:22:13 -070032struct dax_device *alloc_dax(void *private, const char *host,
33 const struct dax_operations *ops);
Dan Williamsef5104242017-05-08 10:55:27 -070034void put_dax(struct dax_device *dax_dev);
Dan Williams976431b2018-03-29 17:22:13 -070035void kill_dax(struct dax_device *dax_dev);
36void dax_write_cache(struct dax_device *dax_dev, bool wc);
37bool dax_write_cache_enabled(struct dax_device *dax_dev);
Dan Williamsef5104242017-05-08 10:55:27 -070038#else
39static inline struct dax_device *dax_get_by_host(const char *host)
40{
41 return NULL;
42}
Dan Williams976431b2018-03-29 17:22:13 -070043static inline struct dax_device *alloc_dax(void *private, const char *host,
44 const struct dax_operations *ops)
45{
46 /*
47 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
48 * NULL is an error or expected.
49 */
50 return NULL;
51}
Dan Williamsef5104242017-05-08 10:55:27 -070052static inline void put_dax(struct dax_device *dax_dev)
53{
54}
Dan Williams976431b2018-03-29 17:22:13 -070055static inline void kill_dax(struct dax_device *dax_dev)
56{
57}
58static inline void dax_write_cache(struct dax_device *dax_dev, bool wc)
59{
60}
61static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)
62{
63 return false;
64}
Dan Williamsef5104242017-05-08 10:55:27 -070065#endif
66
Dan Williamsf44c7762018-03-07 15:26:44 -080067struct writeback_control;
Dan Williamsf5705aa8c2017-05-13 16:31:05 -070068int bdev_dax_pgoff(struct block_device *, sector_t, size_t, pgoff_t *pgoff);
69#if IS_ENABLED(CONFIG_FS_DAX)
Dave Jiang80660f22018-05-30 13:03:46 -070070bool __bdev_dax_supported(struct block_device *bdev, int blocksize);
71static inline bool bdev_dax_supported(struct block_device *bdev, int blocksize)
Dan Williamsf5705aa8c2017-05-13 16:31:05 -070072{
Darrick J. Wongba23cba2018-05-30 13:03:45 -070073 return __bdev_dax_supported(bdev, blocksize);
Dan Williamsf5705aa8c2017-05-13 16:31:05 -070074}
75
76static inline struct dax_device *fs_dax_get_by_host(const char *host)
77{
78 return dax_get_by_host(host);
79}
80
81static inline void fs_put_dax(struct dax_device *dax_dev)
82{
83 put_dax(dax_dev);
84}
85
Dan Williams78f35472017-08-30 09:16:38 -070086struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev);
Dan Williamsf44c7762018-03-07 15:26:44 -080087int dax_writeback_mapping_range(struct address_space *mapping,
88 struct block_device *bdev, struct writeback_control *wbc);
Dan Williams5fac7402018-03-09 17:44:31 -080089
90struct page *dax_layout_busy_page(struct address_space *mapping);
Dan Williamsc2a7d2a2018-07-13 21:50:16 -070091bool dax_lock_mapping_entry(struct page *page);
92void dax_unlock_mapping_entry(struct page *page);
Dan Williamsf5705aa8c2017-05-13 16:31:05 -070093#else
Dave Jiang80660f22018-05-30 13:03:46 -070094static inline bool bdev_dax_supported(struct block_device *bdev,
Darrick J. Wongba23cba2018-05-30 13:03:45 -070095 int blocksize)
Dan Williamsf5705aa8c2017-05-13 16:31:05 -070096{
Dave Jiang80660f22018-05-30 13:03:46 -070097 return false;
Dan Williamsf5705aa8c2017-05-13 16:31:05 -070098}
99
100static inline struct dax_device *fs_dax_get_by_host(const char *host)
101{
102 return NULL;
103}
104
105static inline void fs_put_dax(struct dax_device *dax_dev)
106{
107}
Dan Williams78f35472017-08-30 09:16:38 -0700108
109static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev)
110{
111 return NULL;
112}
Dan Williamsf44c7762018-03-07 15:26:44 -0800113
Dan Williams5fac7402018-03-09 17:44:31 -0800114static inline struct page *dax_layout_busy_page(struct address_space *mapping)
115{
116 return NULL;
117}
118
Dan Williamsf44c7762018-03-07 15:26:44 -0800119static inline int dax_writeback_mapping_range(struct address_space *mapping,
120 struct block_device *bdev, struct writeback_control *wbc)
121{
122 return -EOPNOTSUPP;
123}
Dan Williamsc2a7d2a2018-07-13 21:50:16 -0700124
125static inline bool dax_lock_mapping_entry(struct page *page)
126{
127 if (IS_DAX(page->mapping->host))
128 return true;
129 return false;
130}
131
132static inline void dax_unlock_mapping_entry(struct page *page)
133{
134}
Dan Williamsf5705aa8c2017-05-13 16:31:05 -0700135#endif
136
Dan Williams7b6be842017-04-11 09:49:49 -0700137int dax_read_lock(void);
138void dax_read_unlock(int id);
Dan Williamsc1d6e822017-01-24 23:02:09 -0800139bool dax_alive(struct dax_device *dax_dev);
Dan Williamsc1d6e822017-01-24 23:02:09 -0800140void *dax_get_private(struct dax_device *dax_dev);
Dan Williamsb0686262017-01-26 20:37:35 -0800141long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
142 void **kaddr, pfn_t *pfn);
Dan Williams7e026c82017-05-29 12:57:56 -0700143size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
144 size_t bytes, struct iov_iter *i);
Dan Williamsb3a9a0c2018-05-02 06:46:33 -0700145size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
146 size_t bytes, struct iov_iter *i);
Mikulas Patockac3ca0152017-08-31 21:47:43 -0400147void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
Dan Williams7b6be842017-04-11 09:49:49 -0700148
Ross Zwisler11c59c92016-11-08 11:32:46 +1100149ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
Christoph Hellwig8ff6daa2017-01-27 23:20:26 -0800150 const struct iomap_ops *ops);
Souptick Joarderf77bc3a2018-06-27 23:26:17 -0700151vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
Jan Karac0b24622018-01-07 16:38:43 -0500152 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
Souptick Joarderab77dab2018-06-07 17:04:29 -0700153vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
154 enum page_entry_size pe_size, pfn_t pfn);
Jan Karaac401cc2016-05-12 18:29:18 +0200155int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
Jan Karac6dcf522016-08-10 17:22:44 +0200156int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
157 pgoff_t index);
Dan Williamsd1a5f2b42016-01-28 20:25:31 -0800158
159#ifdef CONFIG_FS_DAX
Dan Williamscccbce62017-01-27 13:31:42 -0800160int __dax_zero_page_range(struct block_device *bdev,
161 struct dax_device *dax_dev, sector_t sector,
Christoph Hellwig679c8bd2016-05-09 10:47:04 +0200162 unsigned int offset, unsigned int length);
Dan Williamsd1a5f2b42016-01-28 20:25:31 -0800163#else
Christoph Hellwig679c8bd2016-05-09 10:47:04 +0200164static inline int __dax_zero_page_range(struct block_device *bdev,
Dan Williamscccbce62017-01-27 13:31:42 -0800165 struct dax_device *dax_dev, sector_t sector,
166 unsigned int offset, unsigned int length)
Christoph Hellwig679c8bd2016-05-09 10:47:04 +0200167{
168 return -ENXIO;
169}
Dan Williamsd1a5f2b42016-01-28 20:25:31 -0800170#endif
171
Ross Zwislerf9fe48b2016-01-22 15:10:40 -0800172static inline bool dax_mapping(struct address_space *mapping)
173{
174 return mapping->host && IS_DAX(mapping->host);
175}
Ross Zwisler7f6d5b52016-02-26 15:19:55 -0800176
Matthew Wilcoxc94c2ac2015-09-08 14:58:40 -0700177#endif