blob: d403f78b706c0a6f8df12aff7c9e2e165b42a383 [file] [log] [blame]
Matthew Wilcoxc94c2ac2015-09-08 14:58:40 -07001#ifndef _LINUX_DAX_H
2#define _LINUX_DAX_H
3
4#include <linux/fs.h>
5#include <linux/mm.h>
Jan Kara4f622932016-05-12 18:29:17 +02006#include <linux/radix-tree.h>
Matthew Wilcoxc94c2ac2015-09-08 14:58:40 -07007#include <asm/pgtable.h>
8
Christoph Hellwiga254e562016-09-19 11:24:49 +10009struct iomap_ops;
Dan Williams6568b082017-01-24 18:44:18 -080010struct dax_device;
11struct dax_operations {
12 /*
13 * direct_access: translate a device-relative
14 * logical-page-offset into an absolute physical pfn. Return the
15 * number of pages available for DAX at that pfn.
16 */
17 long (*direct_access)(struct dax_device *, pgoff_t, long,
18 void **, pfn_t *);
Dan Williams5d61e432017-06-27 13:06:22 -070019 /* copy_from_iter: required operation for fs-dax direct-i/o */
Dan Williams0aed55a2017-05-29 12:22:50 -070020 size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t,
21 struct iov_iter *);
Dan Williams6568b082017-01-24 18:44:18 -080022};
Christoph Hellwiga254e562016-09-19 11:24:49 +100023
Dan Williams6e0c90d2017-06-26 21:28:41 -070024extern struct attribute_group dax_attribute_group;
25
Dan Williamsef5104242017-05-08 10:55:27 -070026#if IS_ENABLED(CONFIG_DAX)
27struct dax_device *dax_get_by_host(const char *host);
28void put_dax(struct dax_device *dax_dev);
29#else
30static inline struct dax_device *dax_get_by_host(const char *host)
31{
32 return NULL;
33}
34
35static inline void put_dax(struct dax_device *dax_dev)
36{
37}
38#endif
39
Dan Williamsf5705aa8c2017-05-13 16:31:05 -070040int bdev_dax_pgoff(struct block_device *, sector_t, size_t, pgoff_t *pgoff);
41#if IS_ENABLED(CONFIG_FS_DAX)
42int __bdev_dax_supported(struct super_block *sb, int blocksize);
43static inline int bdev_dax_supported(struct super_block *sb, int blocksize)
44{
45 return __bdev_dax_supported(sb, blocksize);
46}
47
48static inline struct dax_device *fs_dax_get_by_host(const char *host)
49{
50 return dax_get_by_host(host);
51}
52
53static inline void fs_put_dax(struct dax_device *dax_dev)
54{
55 put_dax(dax_dev);
56}
57
Dan Williams78f35472017-08-30 09:16:38 -070058struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev);
Dan Williamsf5705aa8c2017-05-13 16:31:05 -070059#else
60static inline int bdev_dax_supported(struct super_block *sb, int blocksize)
61{
62 return -EOPNOTSUPP;
63}
64
65static inline struct dax_device *fs_dax_get_by_host(const char *host)
66{
67 return NULL;
68}
69
70static inline void fs_put_dax(struct dax_device *dax_dev)
71{
72}
Dan Williams78f35472017-08-30 09:16:38 -070073
74static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev)
75{
76 return NULL;
77}
Dan Williamsf5705aa8c2017-05-13 16:31:05 -070078#endif
79
Dan Williams7b6be842017-04-11 09:49:49 -070080int dax_read_lock(void);
81void dax_read_unlock(int id);
Dan Williamsc1d6e822017-01-24 23:02:09 -080082struct dax_device *alloc_dax(void *private, const char *host,
83 const struct dax_operations *ops);
Dan Williamsc1d6e822017-01-24 23:02:09 -080084bool dax_alive(struct dax_device *dax_dev);
85void kill_dax(struct dax_device *dax_dev);
86void *dax_get_private(struct dax_device *dax_dev);
Dan Williamsb0686262017-01-26 20:37:35 -080087long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
88 void **kaddr, pfn_t *pfn);
Dan Williams7e026c82017-05-29 12:57:56 -070089size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
90 size_t bytes, struct iov_iter *i);
Mikulas Patockac3ca0152017-08-31 21:47:43 -040091void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
Dan Williams6e0c90d2017-06-26 21:28:41 -070092void dax_write_cache(struct dax_device *dax_dev, bool wc);
Vivek Goyal273752c2017-07-26 09:35:09 -040093bool dax_write_cache_enabled(struct dax_device *dax_dev);
Dan Williams7b6be842017-04-11 09:49:49 -070094
Ross Zwisler11c59c92016-11-08 11:32:46 +110095ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
Christoph Hellwig8ff6daa2017-01-27 23:20:26 -080096 const struct iomap_ops *ops);
Dave Jiangc791ace2017-02-24 14:57:08 -080097int dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
Jan Kara9a0dd422017-11-01 16:36:39 +010098 pfn_t *pfnp, const struct iomap_ops *ops);
Jan Kara71eab6d2017-11-01 16:36:43 +010099int dax_finish_sync_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
100 pfn_t pfn);
Jan Karaac401cc2016-05-12 18:29:18 +0200101int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
Jan Karac6dcf522016-08-10 17:22:44 +0200102int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
103 pgoff_t index);
Dan Williamsd1a5f2b42016-01-28 20:25:31 -0800104
105#ifdef CONFIG_FS_DAX
Dan Williamscccbce62017-01-27 13:31:42 -0800106int __dax_zero_page_range(struct block_device *bdev,
107 struct dax_device *dax_dev, sector_t sector,
Christoph Hellwig679c8bd2016-05-09 10:47:04 +0200108 unsigned int offset, unsigned int length);
Dan Williamsd1a5f2b42016-01-28 20:25:31 -0800109#else
Christoph Hellwig679c8bd2016-05-09 10:47:04 +0200110static inline int __dax_zero_page_range(struct block_device *bdev,
Dan Williamscccbce62017-01-27 13:31:42 -0800111 struct dax_device *dax_dev, sector_t sector,
112 unsigned int offset, unsigned int length)
Christoph Hellwig679c8bd2016-05-09 10:47:04 +0200113{
114 return -ENXIO;
115}
Dan Williamsd1a5f2b42016-01-28 20:25:31 -0800116#endif
117
Ross Zwislerf9fe48b2016-01-22 15:10:40 -0800118static inline bool dax_mapping(struct address_space *mapping)
119{
120 return mapping->host && IS_DAX(mapping->host);
121}
Ross Zwisler7f6d5b52016-02-26 15:19:55 -0800122
123struct writeback_control;
124int dax_writeback_mapping_range(struct address_space *mapping,
125 struct block_device *bdev, struct writeback_control *wbc);
Matthew Wilcoxc94c2ac2015-09-08 14:58:40 -0700126#endif