Commit | Line | Data |
---|---|---|
2ff4bed7 JG |
1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
2 | /* | |
3 | * Copyright (C) 2021 Intel Corporation | |
4 | * Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES | |
5 | */ | |
6 | #ifndef __LINUX_IOMMUFD_H | |
7 | #define __LINUX_IOMMUFD_H | |
8 | ||
9 | #include <linux/types.h> | |
10 | #include <linux/errno.h> | |
11 | #include <linux/err.h> | |
12 | ||
8d40205f | 13 | struct device; |
e8d57210 | 14 | struct iommufd_device; |
8d40205f | 15 | struct page; |
2ff4bed7 | 16 | struct iommufd_ctx; |
8d40205f | 17 | struct iommufd_access; |
2ff4bed7 JG |
18 | struct file; |
19 | ||
e8d57210 JG |
20 | struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx, |
21 | struct device *dev, u32 *id); | |
22 | void iommufd_device_unbind(struct iommufd_device *idev); | |
23 | ||
24 | int iommufd_device_attach(struct iommufd_device *idev, u32 *pt_id); | |
25 | void iommufd_device_detach(struct iommufd_device *idev); | |
26 | ||
8d40205f JG |
27 | struct iommufd_access_ops { |
28 | u8 needs_pin_pages : 1; | |
29 | void (*unmap)(void *data, unsigned long iova, unsigned long length); | |
30 | }; | |
31 | ||
f394576e JG |
32 | enum { |
33 | IOMMUFD_ACCESS_RW_READ = 0, | |
34 | IOMMUFD_ACCESS_RW_WRITE = 1 << 0, | |
35 | /* Set if the caller is in a kthread then rw will use kthread_use_mm() */ | |
36 | IOMMUFD_ACCESS_RW_KTHREAD = 1 << 1, | |
f4b20bb3 JG |
37 | |
38 | /* Only for use by selftest */ | |
39 | __IOMMUFD_ACCESS_RW_SLOW_PATH = 1 << 2, | |
f394576e JG |
40 | }; |
41 | ||
8d40205f | 42 | struct iommufd_access * |
54b47585 | 43 | iommufd_access_create(struct iommufd_ctx *ictx, |
632fda7f | 44 | const struct iommufd_access_ops *ops, void *data, u32 *id); |
8d40205f | 45 | void iommufd_access_destroy(struct iommufd_access *access); |
54b47585 | 46 | int iommufd_access_attach(struct iommufd_access *access, u32 ioas_id); |
8d40205f | 47 | |
2ff4bed7 JG |
48 | void iommufd_ctx_get(struct iommufd_ctx *ictx); |
49 | ||
50 | #if IS_ENABLED(CONFIG_IOMMUFD) | |
51 | struct iommufd_ctx *iommufd_ctx_from_file(struct file *file); | |
52 | void iommufd_ctx_put(struct iommufd_ctx *ictx); | |
8d40205f JG |
53 | |
54 | int iommufd_access_pin_pages(struct iommufd_access *access, unsigned long iova, | |
55 | unsigned long length, struct page **out_pages, | |
56 | unsigned int flags); | |
57 | void iommufd_access_unpin_pages(struct iommufd_access *access, | |
58 | unsigned long iova, unsigned long length); | |
59 | int iommufd_access_rw(struct iommufd_access *access, unsigned long iova, | |
60 | void *data, size_t len, unsigned int flags); | |
c9a397ce JG |
61 | int iommufd_vfio_compat_ioas_get_id(struct iommufd_ctx *ictx, u32 *out_ioas_id); |
62 | int iommufd_vfio_compat_ioas_create(struct iommufd_ctx *ictx); | |
63 | int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx); | |
2ff4bed7 JG |
64 | #else /* !CONFIG_IOMMUFD */ |
65 | static inline struct iommufd_ctx *iommufd_ctx_from_file(struct file *file) | |
66 | { | |
67 | return ERR_PTR(-EOPNOTSUPP); | |
68 | } | |
69 | ||
70 | static inline void iommufd_ctx_put(struct iommufd_ctx *ictx) | |
71 | { | |
72 | } | |
8d40205f JG |
73 | |
74 | static inline int iommufd_access_pin_pages(struct iommufd_access *access, | |
75 | unsigned long iova, | |
76 | unsigned long length, | |
77 | struct page **out_pages, | |
78 | unsigned int flags) | |
79 | { | |
80 | return -EOPNOTSUPP; | |
81 | } | |
82 | ||
83 | static inline void iommufd_access_unpin_pages(struct iommufd_access *access, | |
84 | unsigned long iova, | |
85 | unsigned long length) | |
86 | { | |
87 | } | |
88 | ||
89 | static inline int iommufd_access_rw(struct iommufd_access *access, unsigned long iova, | |
90 | void *data, size_t len, unsigned int flags) | |
91 | { | |
92 | return -EOPNOTSUPP; | |
93 | } | |
d624d665 | 94 | |
c9a397ce JG |
95 | static inline int iommufd_vfio_compat_ioas_create(struct iommufd_ctx *ictx) |
96 | { | |
97 | return -EOPNOTSUPP; | |
98 | } | |
99 | ||
100 | static inline int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx) | |
d624d665 JG |
101 | { |
102 | return -EOPNOTSUPP; | |
103 | } | |
2ff4bed7 JG |
104 | #endif /* CONFIG_IOMMUFD */ |
105 | #endif |