blob: a43b396fb336f65081927d543e320187f6ad5c2b [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)
70int __bdev_dax_supported(struct super_block *sb, int blocksize);
71static inline int bdev_dax_supported(struct super_block *sb, int blocksize)
72{
73 return __bdev_dax_supported(sb, blocksize);
74}
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 Williamsf5705aa8c2017-05-13 16:31:05 -070089#else
90static inline int bdev_dax_supported(struct super_block *sb, int blocksize)
91{
92 return -EOPNOTSUPP;
93}
94
95static inline struct dax_device *fs_dax_get_by_host(const char *host)
96{
97 return NULL;
98}
99
100static inline void fs_put_dax(struct dax_device *dax_dev)
101{
102}
Dan Williams78f35472017-08-30 09:16:38 -0700103
104static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev)
105{
106 return NULL;
107}
Dan Williamsf44c7762018-03-07 15:26:44 -0800108
109static inline int dax_writeback_mapping_range(struct address_space *mapping,
110 struct block_device *bdev, struct writeback_control *wbc)
111{
112 return -EOPNOTSUPP;
113}
Dan Williamsf5705aa8c2017-05-13 16:31:05 -0700114#endif
115
Dan Williams7b6be842017-04-11 09:49:49 -0700116int dax_read_lock(void);
117void dax_read_unlock(int id);
Dan Williamsc1d6e822017-01-24 23:02:09 -0800118bool dax_alive(struct dax_device *dax_dev);
Dan Williamsc1d6e822017-01-24 23:02:09 -0800119void *dax_get_private(struct dax_device *dax_dev);
Dan Williamsb0686262017-01-26 20:37:35 -0800120long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
121 void **kaddr, pfn_t *pfn);
Dan Williams7e026c82017-05-29 12:57:56 -0700122size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
123 size_t bytes, struct iov_iter *i);
Dan Williamsb3a9a0c2018-05-02 06:46:33 -0700124size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
125 size_t bytes, struct iov_iter *i);
Mikulas Patockac3ca0152017-08-31 21:47:43 -0400126void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
Dan Williams7b6be842017-04-11 09:49:49 -0700127
Ross Zwisler11c59c92016-11-08 11:32:46 +1100128ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
Christoph Hellwig8ff6daa2017-01-27 23:20:26 -0800129 const struct iomap_ops *ops);
Dave Jiangc791ace2017-02-24 14:57:08 -0800130int dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
Jan Karac0b24622018-01-07 16:38:43 -0500131 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
Jan Kara71eab6d2017-11-01 16:36:43 +0100132int dax_finish_sync_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
133 pfn_t pfn);
Jan Karaac401cc2016-05-12 18:29:18 +0200134int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
Jan Karac6dcf522016-08-10 17:22:44 +0200135int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
136 pgoff_t index);
Dan Williamsd1a5f2b42016-01-28 20:25:31 -0800137
138#ifdef CONFIG_FS_DAX
Dan Williamscccbce62017-01-27 13:31:42 -0800139int __dax_zero_page_range(struct block_device *bdev,
140 struct dax_device *dax_dev, sector_t sector,
Christoph Hellwig679c8bd2016-05-09 10:47:04 +0200141 unsigned int offset, unsigned int length);
Dan Williamsd1a5f2b42016-01-28 20:25:31 -0800142#else
Christoph Hellwig679c8bd2016-05-09 10:47:04 +0200143static inline int __dax_zero_page_range(struct block_device *bdev,
Dan Williamscccbce62017-01-27 13:31:42 -0800144 struct dax_device *dax_dev, sector_t sector,
145 unsigned int offset, unsigned int length)
Christoph Hellwig679c8bd2016-05-09 10:47:04 +0200146{
147 return -ENXIO;
148}
Dan Williamsd1a5f2b42016-01-28 20:25:31 -0800149#endif
150
Ross Zwislerf9fe48b2016-01-22 15:10:40 -0800151static inline bool dax_mapping(struct address_space *mapping)
152{
153 return mapping->host && IS_DAX(mapping->host);
154}
Ross Zwisler7f6d5b52016-02-26 15:19:55 -0800155
Matthew Wilcoxc94c2ac2015-09-08 14:58:40 -0700156#endif