18cc02d22SChristoph Hellwig /* SPDX-License-Identifier: GPL-2.0-only */
28cc02d22SChristoph Hellwig /*
38cc02d22SChristoph Hellwig * Copyright (C) 2012 Red Hat, Inc. All rights reserved.
48cc02d22SChristoph Hellwig * Author: Alex Williamson <alex.williamson@redhat.com>
58cc02d22SChristoph Hellwig */
6e3bb4de0SJason Gunthorpe #ifndef __VFIO_VFIO_H__
7e3bb4de0SJason Gunthorpe #define __VFIO_VFIO_H__
8e3bb4de0SJason Gunthorpe
99eefba80SYi Liu #include <linux/file.h>
10e3bb4de0SJason Gunthorpe #include <linux/device.h>
11e3bb4de0SJason Gunthorpe #include <linux/cdev.h>
12e3bb4de0SJason Gunthorpe #include <linux/module.h>
13c9a397ceSJason Gunthorpe #include <linux/vfio.h>
14e3bb4de0SJason Gunthorpe
152a3dab19SJason Gunthorpe struct iommufd_ctx;
16e3bb4de0SJason Gunthorpe struct iommu_group;
17cdc71fe4SJason Gunthorpe struct vfio_container;
188cc02d22SChristoph Hellwig
19b1a3b5c6SYi Liu struct vfio_device_file {
20b1a3b5c6SYi Liu struct vfio_device *device;
21839e692fSYi Liu struct vfio_group *group;
2234aeeecdSYi Liu
2382d93f58SYi Liu u8 access_granted;
2431014aefSYi Liu u32 devid; /* only valid when iommufd is valid */
2534aeeecdSYi Liu spinlock_t kvm_ref_lock; /* protect kvm field */
2634aeeecdSYi Liu struct kvm *kvm;
2705f37e1cSYi Liu struct iommufd_ctx *iommufd; /* protected by struct vfio_device_set::lock */
28b1a3b5c6SYi Liu };
29b1a3b5c6SYi Liu
309eefba80SYi Liu void vfio_device_put_registration(struct vfio_device *device);
319eefba80SYi Liu bool vfio_device_try_get_registration(struct vfio_device *device);
3205f37e1cSYi Liu int vfio_df_open(struct vfio_device_file *df);
3305f37e1cSYi Liu void vfio_df_close(struct vfio_device_file *df);
34b1a3b5c6SYi Liu struct vfio_device_file *
35b1a3b5c6SYi Liu vfio_allocate_device_file(struct vfio_device *device);
369eefba80SYi Liu
379eefba80SYi Liu extern const struct file_operations vfio_device_fops;
389eefba80SYi Liu
39*c1cce6d0SYi Liu #ifdef CONFIG_VFIO_NOIOMMU
40*c1cce6d0SYi Liu extern bool vfio_noiommu __read_mostly;
41*c1cce6d0SYi Liu #else
42*c1cce6d0SYi Liu enum { vfio_noiommu = false };
43*c1cce6d0SYi Liu #endif
44*c1cce6d0SYi Liu
45c3c0fa9dSChristoph Hellwig enum vfio_group_type {
46c3c0fa9dSChristoph Hellwig /*
47c3c0fa9dSChristoph Hellwig * Physical device with IOMMU backing.
48c3c0fa9dSChristoph Hellwig */
49c3c0fa9dSChristoph Hellwig VFIO_IOMMU,
50c3c0fa9dSChristoph Hellwig
51c3c0fa9dSChristoph Hellwig /*
52c3c0fa9dSChristoph Hellwig * Virtual device without IOMMU backing. The VFIO core fakes up an
53c3c0fa9dSChristoph Hellwig * iommu_group as the iommu_group sysfs interface is part of the
54c3c0fa9dSChristoph Hellwig * userspace ABI. The user of these devices must not be able to
55c3c0fa9dSChristoph Hellwig * directly trigger unmediated DMA.
56c3c0fa9dSChristoph Hellwig */
57c3c0fa9dSChristoph Hellwig VFIO_EMULATED_IOMMU,
58c3c0fa9dSChristoph Hellwig
59c3c0fa9dSChristoph Hellwig /*
60c3c0fa9dSChristoph Hellwig * Physical device without IOMMU backing. The VFIO core fakes up an
61c3c0fa9dSChristoph Hellwig * iommu_group as the iommu_group sysfs interface is part of the
62c3c0fa9dSChristoph Hellwig * userspace ABI. Users can trigger unmediated DMA by the device,
63c3c0fa9dSChristoph Hellwig * usage is highly dangerous, requires an explicit opt-in and will
64c3c0fa9dSChristoph Hellwig * taint the kernel.
65c3c0fa9dSChristoph Hellwig */
66c3c0fa9dSChristoph Hellwig VFIO_NO_IOMMU,
67c3c0fa9dSChristoph Hellwig };
68c3c0fa9dSChristoph Hellwig
69*c1cce6d0SYi Liu #if IS_ENABLED(CONFIG_VFIO_GROUP)
70cdc71fe4SJason Gunthorpe struct vfio_group {
71cdc71fe4SJason Gunthorpe struct device dev;
72cdc71fe4SJason Gunthorpe struct cdev cdev;
73ca5f21b2SJason Gunthorpe /*
74ca5f21b2SJason Gunthorpe * When drivers is non-zero a driver is attached to the struct device
75ca5f21b2SJason Gunthorpe * that provided the iommu_group and thus the iommu_group is a valid
76ca5f21b2SJason Gunthorpe * pointer. When drivers is 0 the driver is being detached. Once users
77ca5f21b2SJason Gunthorpe * reaches 0 then the iommu_group is invalid.
78ca5f21b2SJason Gunthorpe */
79ca5f21b2SJason Gunthorpe refcount_t drivers;
80cdc71fe4SJason Gunthorpe unsigned int container_users;
81cdc71fe4SJason Gunthorpe struct iommu_group *iommu_group;
82cdc71fe4SJason Gunthorpe struct vfio_container *container;
83cdc71fe4SJason Gunthorpe struct list_head device_list;
84cdc71fe4SJason Gunthorpe struct mutex device_lock;
85cdc71fe4SJason Gunthorpe struct list_head vfio_next;
86e5a9ec7eSJason Gunthorpe #if IS_ENABLED(CONFIG_VFIO_CONTAINER)
87cdc71fe4SJason Gunthorpe struct list_head container_next;
88e5a9ec7eSJason Gunthorpe #endif
89cdc71fe4SJason Gunthorpe enum vfio_group_type type;
90c82e81abSJason Gunthorpe struct mutex group_lock;
91cdc71fe4SJason Gunthorpe struct kvm *kvm;
92cdc71fe4SJason Gunthorpe struct file *opened_file;
93cdc71fe4SJason Gunthorpe struct blocking_notifier_head notifier;
942a3dab19SJason Gunthorpe struct iommufd_ctx *iommufd;
952b48f52fSMatthew Rosato spinlock_t kvm_ref_lock;
96270bf4c0SYi Liu unsigned int cdev_device_open_cnt;
97cdc71fe4SJason Gunthorpe };
98cdc71fe4SJason Gunthorpe
99270bf4c0SYi Liu int vfio_device_block_group(struct vfio_device *device);
100270bf4c0SYi Liu void vfio_device_unblock_group(struct vfio_device *device);
1019eefba80SYi Liu int vfio_device_set_group(struct vfio_device *device,
1029eefba80SYi Liu enum vfio_group_type type);
1039eefba80SYi Liu void vfio_device_remove_group(struct vfio_device *device);
1049eefba80SYi Liu void vfio_device_group_register(struct vfio_device *device);
1059eefba80SYi Liu void vfio_device_group_unregister(struct vfio_device *device);
1069eefba80SYi Liu int vfio_device_group_use_iommu(struct vfio_device *device);
1079eefba80SYi Liu void vfio_device_group_unuse_iommu(struct vfio_device *device);
10805f37e1cSYi Liu void vfio_df_group_close(struct vfio_device_file *df);
109b1a59be8SYi Liu struct vfio_group *vfio_group_from_file(struct file *file);
110b1a59be8SYi Liu bool vfio_group_enforced_coherent(struct vfio_group *group);
111b1a59be8SYi Liu void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm);
1129eefba80SYi Liu bool vfio_device_has_container(struct vfio_device *device);
1139eefba80SYi Liu int __init vfio_group_init(void);
1149eefba80SYi Liu void vfio_group_cleanup(void);
1159eefba80SYi Liu
vfio_device_is_noiommu(struct vfio_device * vdev)116c9a397ceSJason Gunthorpe static inline bool vfio_device_is_noiommu(struct vfio_device *vdev)
117c9a397ceSJason Gunthorpe {
118c9a397ceSJason Gunthorpe return IS_ENABLED(CONFIG_VFIO_NOIOMMU) &&
119c9a397ceSJason Gunthorpe vdev->group->type == VFIO_NO_IOMMU;
120c9a397ceSJason Gunthorpe }
121*c1cce6d0SYi Liu #else
122*c1cce6d0SYi Liu struct vfio_group;
123*c1cce6d0SYi Liu
vfio_device_block_group(struct vfio_device * device)124*c1cce6d0SYi Liu static inline int vfio_device_block_group(struct vfio_device *device)
125*c1cce6d0SYi Liu {
126*c1cce6d0SYi Liu return 0;
127*c1cce6d0SYi Liu }
128*c1cce6d0SYi Liu
vfio_device_unblock_group(struct vfio_device * device)129*c1cce6d0SYi Liu static inline void vfio_device_unblock_group(struct vfio_device *device)
130*c1cce6d0SYi Liu {
131*c1cce6d0SYi Liu }
132*c1cce6d0SYi Liu
vfio_device_set_group(struct vfio_device * device,enum vfio_group_type type)133*c1cce6d0SYi Liu static inline int vfio_device_set_group(struct vfio_device *device,
134*c1cce6d0SYi Liu enum vfio_group_type type)
135*c1cce6d0SYi Liu {
136*c1cce6d0SYi Liu return 0;
137*c1cce6d0SYi Liu }
138*c1cce6d0SYi Liu
vfio_device_remove_group(struct vfio_device * device)139*c1cce6d0SYi Liu static inline void vfio_device_remove_group(struct vfio_device *device)
140*c1cce6d0SYi Liu {
141*c1cce6d0SYi Liu }
142*c1cce6d0SYi Liu
vfio_device_group_register(struct vfio_device * device)143*c1cce6d0SYi Liu static inline void vfio_device_group_register(struct vfio_device *device)
144*c1cce6d0SYi Liu {
145*c1cce6d0SYi Liu }
146*c1cce6d0SYi Liu
vfio_device_group_unregister(struct vfio_device * device)147*c1cce6d0SYi Liu static inline void vfio_device_group_unregister(struct vfio_device *device)
148*c1cce6d0SYi Liu {
149*c1cce6d0SYi Liu }
150*c1cce6d0SYi Liu
vfio_device_group_use_iommu(struct vfio_device * device)151*c1cce6d0SYi Liu static inline int vfio_device_group_use_iommu(struct vfio_device *device)
152*c1cce6d0SYi Liu {
153*c1cce6d0SYi Liu return -EOPNOTSUPP;
154*c1cce6d0SYi Liu }
155*c1cce6d0SYi Liu
vfio_device_group_unuse_iommu(struct vfio_device * device)156*c1cce6d0SYi Liu static inline void vfio_device_group_unuse_iommu(struct vfio_device *device)
157*c1cce6d0SYi Liu {
158*c1cce6d0SYi Liu }
159*c1cce6d0SYi Liu
vfio_df_group_close(struct vfio_device_file * df)160*c1cce6d0SYi Liu static inline void vfio_df_group_close(struct vfio_device_file *df)
161*c1cce6d0SYi Liu {
162*c1cce6d0SYi Liu }
163*c1cce6d0SYi Liu
vfio_group_from_file(struct file * file)164*c1cce6d0SYi Liu static inline struct vfio_group *vfio_group_from_file(struct file *file)
165*c1cce6d0SYi Liu {
166*c1cce6d0SYi Liu return NULL;
167*c1cce6d0SYi Liu }
168*c1cce6d0SYi Liu
vfio_group_enforced_coherent(struct vfio_group * group)169*c1cce6d0SYi Liu static inline bool vfio_group_enforced_coherent(struct vfio_group *group)
170*c1cce6d0SYi Liu {
171*c1cce6d0SYi Liu return true;
172*c1cce6d0SYi Liu }
173*c1cce6d0SYi Liu
vfio_group_set_kvm(struct vfio_group * group,struct kvm * kvm)174*c1cce6d0SYi Liu static inline void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm)
175*c1cce6d0SYi Liu {
176*c1cce6d0SYi Liu }
177*c1cce6d0SYi Liu
vfio_device_has_container(struct vfio_device * device)178*c1cce6d0SYi Liu static inline bool vfio_device_has_container(struct vfio_device *device)
179*c1cce6d0SYi Liu {
180*c1cce6d0SYi Liu return false;
181*c1cce6d0SYi Liu }
182*c1cce6d0SYi Liu
vfio_group_init(void)183*c1cce6d0SYi Liu static inline int __init vfio_group_init(void)
184*c1cce6d0SYi Liu {
185*c1cce6d0SYi Liu return 0;
186*c1cce6d0SYi Liu }
187*c1cce6d0SYi Liu
vfio_group_cleanup(void)188*c1cce6d0SYi Liu static inline void vfio_group_cleanup(void)
189*c1cce6d0SYi Liu {
190*c1cce6d0SYi Liu }
191*c1cce6d0SYi Liu
vfio_device_is_noiommu(struct vfio_device * vdev)192*c1cce6d0SYi Liu static inline bool vfio_device_is_noiommu(struct vfio_device *vdev)
193*c1cce6d0SYi Liu {
194*c1cce6d0SYi Liu return false;
195*c1cce6d0SYi Liu }
196*c1cce6d0SYi Liu #endif /* CONFIG_VFIO_GROUP */
197c9a397ceSJason Gunthorpe
198e5a9ec7eSJason Gunthorpe #if IS_ENABLED(CONFIG_VFIO_CONTAINER)
1998cc02d22SChristoph Hellwig /**
2008cc02d22SChristoph Hellwig * struct vfio_iommu_driver_ops - VFIO IOMMU driver callbacks
2018cc02d22SChristoph Hellwig */
2028cc02d22SChristoph Hellwig struct vfio_iommu_driver_ops {
2038cc02d22SChristoph Hellwig char *name;
2048cc02d22SChristoph Hellwig struct module *owner;
2058cc02d22SChristoph Hellwig void *(*open)(unsigned long arg);
2068cc02d22SChristoph Hellwig void (*release)(void *iommu_data);
2078cc02d22SChristoph Hellwig long (*ioctl)(void *iommu_data, unsigned int cmd,
2088cc02d22SChristoph Hellwig unsigned long arg);
2098cc02d22SChristoph Hellwig int (*attach_group)(void *iommu_data,
210c3c0fa9dSChristoph Hellwig struct iommu_group *group,
211c3c0fa9dSChristoph Hellwig enum vfio_group_type);
2128cc02d22SChristoph Hellwig void (*detach_group)(void *iommu_data,
2138cc02d22SChristoph Hellwig struct iommu_group *group);
2148cc02d22SChristoph Hellwig int (*pin_pages)(void *iommu_data,
2158cc02d22SChristoph Hellwig struct iommu_group *group,
21644abdd16SNicolin Chen dma_addr_t user_iova,
2178cc02d22SChristoph Hellwig int npage, int prot,
21834a255e6SNicolin Chen struct page **pages);
219e8f90717SNicolin Chen void (*unpin_pages)(void *iommu_data,
22044abdd16SNicolin Chen dma_addr_t user_iova, int npage);
2218cfc5b60SJason Gunthorpe void (*register_device)(void *iommu_data,
2228cfc5b60SJason Gunthorpe struct vfio_device *vdev);
2238cfc5b60SJason Gunthorpe void (*unregister_device)(void *iommu_data,
2248cfc5b60SJason Gunthorpe struct vfio_device *vdev);
2258cc02d22SChristoph Hellwig int (*dma_rw)(void *iommu_data, dma_addr_t user_iova,
2268cc02d22SChristoph Hellwig void *data, size_t count, bool write);
2278cc02d22SChristoph Hellwig struct iommu_domain *(*group_iommu_domain)(void *iommu_data,
2288cc02d22SChristoph Hellwig struct iommu_group *group);
2298cc02d22SChristoph Hellwig };
2308cc02d22SChristoph Hellwig
231cdc71fe4SJason Gunthorpe struct vfio_iommu_driver {
232cdc71fe4SJason Gunthorpe const struct vfio_iommu_driver_ops *ops;
233cdc71fe4SJason Gunthorpe struct list_head vfio_next;
234cdc71fe4SJason Gunthorpe };
235cdc71fe4SJason Gunthorpe
2368cc02d22SChristoph Hellwig int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops);
2378cc02d22SChristoph Hellwig void vfio_unregister_iommu_driver(const struct vfio_iommu_driver_ops *ops);
238e3bb4de0SJason Gunthorpe
239cdc71fe4SJason Gunthorpe struct vfio_container *vfio_container_from_file(struct file *filep);
24004f930c3SJason Gunthorpe int vfio_group_use_container(struct vfio_group *group);
24104f930c3SJason Gunthorpe void vfio_group_unuse_container(struct vfio_group *group);
242cdc71fe4SJason Gunthorpe int vfio_container_attach_group(struct vfio_container *container,
243cdc71fe4SJason Gunthorpe struct vfio_group *group);
244cdc71fe4SJason Gunthorpe void vfio_group_detach_container(struct vfio_group *group);
245cdc71fe4SJason Gunthorpe void vfio_device_container_register(struct vfio_device *device);
246cdc71fe4SJason Gunthorpe void vfio_device_container_unregister(struct vfio_device *device);
2478da7a0e7SYi Liu int vfio_device_container_pin_pages(struct vfio_device *device,
2488da7a0e7SYi Liu dma_addr_t iova, int npage,
2498da7a0e7SYi Liu int prot, struct page **pages);
2508da7a0e7SYi Liu void vfio_device_container_unpin_pages(struct vfio_device *device,
2514741f2e9SJason Gunthorpe dma_addr_t iova, int npage);
2528da7a0e7SYi Liu int vfio_device_container_dma_rw(struct vfio_device *device,
2538da7a0e7SYi Liu dma_addr_t iova, void *data,
2548da7a0e7SYi Liu size_t len, bool write);
2554741f2e9SJason Gunthorpe
256cdc71fe4SJason Gunthorpe int __init vfio_container_init(void);
257cdc71fe4SJason Gunthorpe void vfio_container_cleanup(void);
258e5a9ec7eSJason Gunthorpe #else
259e5a9ec7eSJason Gunthorpe static inline struct vfio_container *
vfio_container_from_file(struct file * filep)260e5a9ec7eSJason Gunthorpe vfio_container_from_file(struct file *filep)
261e5a9ec7eSJason Gunthorpe {
262e5a9ec7eSJason Gunthorpe return NULL;
263e5a9ec7eSJason Gunthorpe }
264e5a9ec7eSJason Gunthorpe
vfio_group_use_container(struct vfio_group * group)265e5a9ec7eSJason Gunthorpe static inline int vfio_group_use_container(struct vfio_group *group)
266e5a9ec7eSJason Gunthorpe {
267e5a9ec7eSJason Gunthorpe return -EOPNOTSUPP;
268e5a9ec7eSJason Gunthorpe }
269e5a9ec7eSJason Gunthorpe
vfio_group_unuse_container(struct vfio_group * group)270e5a9ec7eSJason Gunthorpe static inline void vfio_group_unuse_container(struct vfio_group *group)
271e5a9ec7eSJason Gunthorpe {
272e5a9ec7eSJason Gunthorpe }
273e5a9ec7eSJason Gunthorpe
vfio_container_attach_group(struct vfio_container * container,struct vfio_group * group)274e5a9ec7eSJason Gunthorpe static inline int vfio_container_attach_group(struct vfio_container *container,
275e5a9ec7eSJason Gunthorpe struct vfio_group *group)
276e5a9ec7eSJason Gunthorpe {
277e5a9ec7eSJason Gunthorpe return -EOPNOTSUPP;
278e5a9ec7eSJason Gunthorpe }
279e5a9ec7eSJason Gunthorpe
vfio_group_detach_container(struct vfio_group * group)280e5a9ec7eSJason Gunthorpe static inline void vfio_group_detach_container(struct vfio_group *group)
281e5a9ec7eSJason Gunthorpe {
282e5a9ec7eSJason Gunthorpe }
283e5a9ec7eSJason Gunthorpe
vfio_device_container_register(struct vfio_device * device)284e5a9ec7eSJason Gunthorpe static inline void vfio_device_container_register(struct vfio_device *device)
285e5a9ec7eSJason Gunthorpe {
286e5a9ec7eSJason Gunthorpe }
287e5a9ec7eSJason Gunthorpe
vfio_device_container_unregister(struct vfio_device * device)288e5a9ec7eSJason Gunthorpe static inline void vfio_device_container_unregister(struct vfio_device *device)
289e5a9ec7eSJason Gunthorpe {
290e5a9ec7eSJason Gunthorpe }
291e5a9ec7eSJason Gunthorpe
vfio_device_container_pin_pages(struct vfio_device * device,dma_addr_t iova,int npage,int prot,struct page ** pages)2928da7a0e7SYi Liu static inline int vfio_device_container_pin_pages(struct vfio_device *device,
2938da7a0e7SYi Liu dma_addr_t iova, int npage,
2948da7a0e7SYi Liu int prot, struct page **pages)
295e5a9ec7eSJason Gunthorpe {
296e5a9ec7eSJason Gunthorpe return -EOPNOTSUPP;
297e5a9ec7eSJason Gunthorpe }
298e5a9ec7eSJason Gunthorpe
vfio_device_container_unpin_pages(struct vfio_device * device,dma_addr_t iova,int npage)2998da7a0e7SYi Liu static inline void vfio_device_container_unpin_pages(struct vfio_device *device,
300e5a9ec7eSJason Gunthorpe dma_addr_t iova, int npage)
301e5a9ec7eSJason Gunthorpe {
302e5a9ec7eSJason Gunthorpe }
303e5a9ec7eSJason Gunthorpe
vfio_device_container_dma_rw(struct vfio_device * device,dma_addr_t iova,void * data,size_t len,bool write)3048da7a0e7SYi Liu static inline int vfio_device_container_dma_rw(struct vfio_device *device,
3058da7a0e7SYi Liu dma_addr_t iova, void *data,
3068da7a0e7SYi Liu size_t len, bool write)
307e5a9ec7eSJason Gunthorpe {
308e5a9ec7eSJason Gunthorpe return -EOPNOTSUPP;
309e5a9ec7eSJason Gunthorpe }
310e5a9ec7eSJason Gunthorpe
vfio_container_init(void)311e5a9ec7eSJason Gunthorpe static inline int vfio_container_init(void)
312e5a9ec7eSJason Gunthorpe {
313e5a9ec7eSJason Gunthorpe return 0;
314e5a9ec7eSJason Gunthorpe }
vfio_container_cleanup(void)315e5a9ec7eSJason Gunthorpe static inline void vfio_container_cleanup(void)
316e5a9ec7eSJason Gunthorpe {
317e5a9ec7eSJason Gunthorpe }
318e5a9ec7eSJason Gunthorpe #endif
319cdc71fe4SJason Gunthorpe
320a4d1f91dSJason Gunthorpe #if IS_ENABLED(CONFIG_IOMMUFD)
3216086efe7SYi Liu bool vfio_iommufd_device_has_compat_ioas(struct vfio_device *vdev,
3226086efe7SYi Liu struct iommufd_ctx *ictx);
32331014aefSYi Liu int vfio_df_iommufd_bind(struct vfio_device_file *df);
32431014aefSYi Liu void vfio_df_iommufd_unbind(struct vfio_device_file *df);
3256f240ee6SYi Liu int vfio_iommufd_compat_attach_ioas(struct vfio_device *device,
3266f240ee6SYi Liu struct iommufd_ctx *ictx);
327a4d1f91dSJason Gunthorpe #else
3286086efe7SYi Liu static inline bool
vfio_iommufd_device_has_compat_ioas(struct vfio_device * vdev,struct iommufd_ctx * ictx)3296086efe7SYi Liu vfio_iommufd_device_has_compat_ioas(struct vfio_device *vdev,
3306086efe7SYi Liu struct iommufd_ctx *ictx)
3316086efe7SYi Liu {
3326086efe7SYi Liu return false;
3336086efe7SYi Liu }
3346086efe7SYi Liu
vfio_df_iommufd_bind(struct vfio_device_file * fd)33531014aefSYi Liu static inline int vfio_df_iommufd_bind(struct vfio_device_file *fd)
336a4d1f91dSJason Gunthorpe {
337a4d1f91dSJason Gunthorpe return -EOPNOTSUPP;
338a4d1f91dSJason Gunthorpe }
339a4d1f91dSJason Gunthorpe
vfio_df_iommufd_unbind(struct vfio_device_file * df)34031014aefSYi Liu static inline void vfio_df_iommufd_unbind(struct vfio_device_file *df)
341a4d1f91dSJason Gunthorpe {
342a4d1f91dSJason Gunthorpe }
3436f240ee6SYi Liu
3446f240ee6SYi Liu static inline int
vfio_iommufd_compat_attach_ioas(struct vfio_device * device,struct iommufd_ctx * ictx)3456f240ee6SYi Liu vfio_iommufd_compat_attach_ioas(struct vfio_device *device,
3466f240ee6SYi Liu struct iommufd_ctx *ictx)
3476f240ee6SYi Liu {
3486f240ee6SYi Liu return -EOPNOTSUPP;
3496f240ee6SYi Liu }
350a4d1f91dSJason Gunthorpe #endif
351a4d1f91dSJason Gunthorpe
352b290a05fSYi Liu int vfio_df_ioctl_attach_pt(struct vfio_device_file *df,
353b290a05fSYi Liu struct vfio_device_attach_iommufd_pt __user *arg);
354b290a05fSYi Liu int vfio_df_ioctl_detach_pt(struct vfio_device_file *df,
355b290a05fSYi Liu struct vfio_device_detach_iommufd_pt __user *arg);
356b290a05fSYi Liu
3578b6f173aSYi Liu #if IS_ENABLED(CONFIG_VFIO_DEVICE_CDEV)
3588b6f173aSYi Liu void vfio_init_device_cdev(struct vfio_device *device);
3598b6f173aSYi Liu
vfio_device_add(struct vfio_device * device)3608b6f173aSYi Liu static inline int vfio_device_add(struct vfio_device *device)
3618b6f173aSYi Liu {
3628b6f173aSYi Liu /* cdev does not support noiommu device */
3638b6f173aSYi Liu if (vfio_device_is_noiommu(device))
3648b6f173aSYi Liu return device_add(&device->device);
3658b6f173aSYi Liu vfio_init_device_cdev(device);
3668b6f173aSYi Liu return cdev_device_add(&device->cdev, &device->device);
3678b6f173aSYi Liu }
3688b6f173aSYi Liu
vfio_device_del(struct vfio_device * device)3698b6f173aSYi Liu static inline void vfio_device_del(struct vfio_device *device)
3708b6f173aSYi Liu {
3718b6f173aSYi Liu if (vfio_device_is_noiommu(device))
3728b6f173aSYi Liu device_del(&device->device);
3738b6f173aSYi Liu else
3748b6f173aSYi Liu cdev_device_del(&device->cdev, &device->device);
3758b6f173aSYi Liu }
3768b6f173aSYi Liu
3778b6f173aSYi Liu int vfio_device_fops_cdev_open(struct inode *inode, struct file *filep);
3785fcc2696SYi Liu long vfio_df_ioctl_bind_iommufd(struct vfio_device_file *df,
3795fcc2696SYi Liu struct vfio_device_bind_iommufd __user *arg);
3805fcc2696SYi Liu void vfio_df_unbind_iommufd(struct vfio_device_file *df);
3818b6f173aSYi Liu int vfio_cdev_init(struct class *device_class);
3828b6f173aSYi Liu void vfio_cdev_cleanup(void);
3838b6f173aSYi Liu #else
vfio_init_device_cdev(struct vfio_device * device)3848b6f173aSYi Liu static inline void vfio_init_device_cdev(struct vfio_device *device)
3858b6f173aSYi Liu {
3868b6f173aSYi Liu }
3878b6f173aSYi Liu
vfio_device_add(struct vfio_device * device)3888b6f173aSYi Liu static inline int vfio_device_add(struct vfio_device *device)
3898b6f173aSYi Liu {
3908b6f173aSYi Liu return device_add(&device->device);
3918b6f173aSYi Liu }
3928b6f173aSYi Liu
vfio_device_del(struct vfio_device * device)3938b6f173aSYi Liu static inline void vfio_device_del(struct vfio_device *device)
3948b6f173aSYi Liu {
3958b6f173aSYi Liu device_del(&device->device);
3968b6f173aSYi Liu }
3978b6f173aSYi Liu
vfio_device_fops_cdev_open(struct inode * inode,struct file * filep)3988b6f173aSYi Liu static inline int vfio_device_fops_cdev_open(struct inode *inode,
3998b6f173aSYi Liu struct file *filep)
4008b6f173aSYi Liu {
4018b6f173aSYi Liu return 0;
4028b6f173aSYi Liu }
4038b6f173aSYi Liu
vfio_df_ioctl_bind_iommufd(struct vfio_device_file * df,struct vfio_device_bind_iommufd __user * arg)4045fcc2696SYi Liu static inline long vfio_df_ioctl_bind_iommufd(struct vfio_device_file *df,
4055fcc2696SYi Liu struct vfio_device_bind_iommufd __user *arg)
4065fcc2696SYi Liu {
4075fcc2696SYi Liu return -ENOTTY;
4085fcc2696SYi Liu }
4095fcc2696SYi Liu
vfio_df_unbind_iommufd(struct vfio_device_file * df)4105fcc2696SYi Liu static inline void vfio_df_unbind_iommufd(struct vfio_device_file *df)
4115fcc2696SYi Liu {
4125fcc2696SYi Liu }
4135fcc2696SYi Liu
vfio_cdev_init(struct class * device_class)4148b6f173aSYi Liu static inline int vfio_cdev_init(struct class *device_class)
4158b6f173aSYi Liu {
4168b6f173aSYi Liu return 0;
4178b6f173aSYi Liu }
4188b6f173aSYi Liu
vfio_cdev_cleanup(void)4198b6f173aSYi Liu static inline void vfio_cdev_cleanup(void)
4208b6f173aSYi Liu {
4218b6f173aSYi Liu }
4228b6f173aSYi Liu #endif /* CONFIG_VFIO_DEVICE_CDEV */
4238b6f173aSYi Liu
424e2d55709SJason Gunthorpe #if IS_ENABLED(CONFIG_VFIO_VIRQFD)
425e2d55709SJason Gunthorpe int __init vfio_virqfd_init(void);
426e2d55709SJason Gunthorpe void vfio_virqfd_exit(void);
427e2d55709SJason Gunthorpe #else
vfio_virqfd_init(void)428e2d55709SJason Gunthorpe static inline int __init vfio_virqfd_init(void)
429e2d55709SJason Gunthorpe {
430e2d55709SJason Gunthorpe return 0;
431e2d55709SJason Gunthorpe }
vfio_virqfd_exit(void)432e2d55709SJason Gunthorpe static inline void vfio_virqfd_exit(void)
433e2d55709SJason Gunthorpe {
434e2d55709SJason Gunthorpe }
435e2d55709SJason Gunthorpe #endif
436e2d55709SJason Gunthorpe
4372b48f52fSMatthew Rosato #ifdef CONFIG_HAVE_KVM
4385c6de3eaSYi Liu void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm);
4392b48f52fSMatthew Rosato void vfio_device_put_kvm(struct vfio_device *device);
4402b48f52fSMatthew Rosato #else
vfio_device_get_kvm_safe(struct vfio_device * device,struct kvm * kvm)4415c6de3eaSYi Liu static inline void vfio_device_get_kvm_safe(struct vfio_device *device,
4422b48f52fSMatthew Rosato struct kvm *kvm)
4432b48f52fSMatthew Rosato {
4442b48f52fSMatthew Rosato }
4452b48f52fSMatthew Rosato
vfio_device_put_kvm(struct vfio_device * device)4462b48f52fSMatthew Rosato static inline void vfio_device_put_kvm(struct vfio_device *device)
4472b48f52fSMatthew Rosato {
4482b48f52fSMatthew Rosato }
4492b48f52fSMatthew Rosato #endif
4502b48f52fSMatthew Rosato
451e3bb4de0SJason Gunthorpe #endif
452