1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2cba3345cSAlex Williamson /*
3cba3345cSAlex Williamson * VFIO API definition
4cba3345cSAlex Williamson *
5cba3345cSAlex Williamson * Copyright (C) 2012 Red Hat, Inc. All rights reserved.
6cba3345cSAlex Williamson * Author: Alex Williamson <alex.williamson@redhat.com>
7cba3345cSAlex Williamson */
8cba3345cSAlex Williamson #ifndef VFIO_H
9cba3345cSAlex Williamson #define VFIO_H
10cba3345cSAlex Williamson
11cba3345cSAlex Williamson
12cba3345cSAlex Williamson #include <linux/iommu.h>
13cba3345cSAlex Williamson #include <linux/mm.h>
147e992d69SAntonios Motakis #include <linux/workqueue.h>
157e992d69SAntonios Motakis #include <linux/poll.h>
168b6f173aSYi Liu #include <linux/cdev.h>
17607ca46eSDavid Howells #include <uapi/linux/vfio.h>
1880c4b92aSYishai Hadas #include <linux/iova_bitmap.h>
19cba3345cSAlex Williamson
20ba70a89fSJason Gunthorpe struct kvm;
21a4d1f91dSJason Gunthorpe struct iommufd_ctx;
22a4d1f91dSJason Gunthorpe struct iommufd_device;
234741f2e9SJason Gunthorpe struct iommufd_access;
24ba70a89fSJason Gunthorpe
252fd585f4SJason Gunthorpe /*
262fd585f4SJason Gunthorpe * VFIO devices can be placed in a set, this allows all devices to share this
272fd585f4SJason Gunthorpe * structure and the VFIO core will provide a lock that is held around
282fd585f4SJason Gunthorpe * open_device()/close_device() for all devices in the set.
292fd585f4SJason Gunthorpe */
302fd585f4SJason Gunthorpe struct vfio_device_set {
312fd585f4SJason Gunthorpe void *set_id;
322fd585f4SJason Gunthorpe struct mutex lock;
332fd585f4SJason Gunthorpe struct list_head device_list;
342fd585f4SJason Gunthorpe unsigned int device_count;
352fd585f4SJason Gunthorpe };
362fd585f4SJason Gunthorpe
370bfc6a4eSJason Gunthorpe struct vfio_device {
380bfc6a4eSJason Gunthorpe struct device *dev;
390bfc6a4eSJason Gunthorpe const struct vfio_device_ops *ops;
406e97eba8SYishai Hadas /*
4180c4b92aSYishai Hadas * mig_ops/log_ops is a static property of the vfio_device which must
4280c4b92aSYishai Hadas * be set prior to registering the vfio_device.
436e97eba8SYishai Hadas */
446e97eba8SYishai Hadas const struct vfio_migration_ops *mig_ops;
4580c4b92aSYishai Hadas const struct vfio_log_ops *log_ops;
46c1cce6d0SYi Liu #if IS_ENABLED(CONFIG_VFIO_GROUP)
470bfc6a4eSJason Gunthorpe struct vfio_group *group;
48c1cce6d0SYi Liu struct list_head group_next;
49c1cce6d0SYi Liu struct list_head iommu_entry;
50c1cce6d0SYi Liu #endif
512fd585f4SJason Gunthorpe struct vfio_device_set *dev_set;
522fd585f4SJason Gunthorpe struct list_head dev_set_list;
538cb3d83bSJason Gunthorpe unsigned int migration_flags;
54421cfe65SMatthew Rosato struct kvm *kvm;
550bfc6a4eSJason Gunthorpe
560bfc6a4eSJason Gunthorpe /* Members below here are private, not for driver use */
573c28a761SYi Liu unsigned int index;
583c28a761SYi Liu struct device device; /* device.kref covers object life circle */
598b6f173aSYi Liu #if IS_ENABLED(CONFIG_VFIO_DEVICE_CDEV)
608b6f173aSYi Liu struct cdev cdev;
618b6f173aSYi Liu #endif
62cb9ff3f3SKevin Tian refcount_t refcount; /* user count on registered device*/
632fd585f4SJason Gunthorpe unsigned int open_count;
640bfc6a4eSJason Gunthorpe struct completion comp;
654741f2e9SJason Gunthorpe struct iommufd_access *iommufd_access;
662b48f52fSMatthew Rosato void (*put_kvm)(struct kvm *kvm);
67a4d1f91dSJason Gunthorpe #if IS_ENABLED(CONFIG_IOMMUFD)
68a4d1f91dSJason Gunthorpe struct iommufd_device *iommufd_device;
695fcc2696SYi Liu u8 iommufd_attached:1;
70a4d1f91dSJason Gunthorpe #endif
715fcc2696SYi Liu u8 cdev_opened:1;
720bfc6a4eSJason Gunthorpe };
730bfc6a4eSJason Gunthorpe
74cba3345cSAlex Williamson /**
75cba3345cSAlex Williamson * struct vfio_device_ops - VFIO bus driver device callbacks
76cba3345cSAlex Williamson *
7738e4614cSSimon Horman * @name: Name of the device driver.
78cb9ff3f3SKevin Tian * @init: initialize private fields in device structure
79cb9ff3f3SKevin Tian * @release: Reclaim private fields in device structure
80fae90680SYi Liu * @bind_iommufd: Called when binding the device to an iommufd
81fae90680SYi Liu * @unbind_iommufd: Opposite of bind_iommufd
82fae90680SYi Liu * @attach_ioas: Called when attaching device to an IOAS/HWPT managed by the
839048c734SYi Liu * bound iommufd. Undo in unbind_iommufd if @detach_ioas is not
849048c734SYi Liu * called.
859048c734SYi Liu * @detach_ioas: Opposite of attach_ioas
862fd585f4SJason Gunthorpe * @open_device: Called when the first file descriptor is opened for this device
872fd585f4SJason Gunthorpe * @close_device: Opposite of open_device
88cba3345cSAlex Williamson * @read: Perform read(2) on device file descriptor
89cba3345cSAlex Williamson * @write: Perform write(2) on device file descriptor
90cba3345cSAlex Williamson * @ioctl: Perform ioctl(2) on device file descriptor, supporting VFIO_DEVICE_*
91cba3345cSAlex Williamson * operations documented below
92cba3345cSAlex Williamson * @mmap: Perform mmap(2) on a region of the device file descriptor
9313060b64SAlex Williamson * @request: Request for the bus driver to release the device
945f3874c2SAlex Williamson * @match: Optional device name match callback (return: 0 for no-match, >0 for
955f3874c2SAlex Williamson * match, -errno for abort (ex. match with insufficient or incorrect
965f3874c2SAlex Williamson * additional args)
97ce4b4657SJason Gunthorpe * @dma_unmap: Called when userspace unmaps IOVA from the container
98ce4b4657SJason Gunthorpe * this device is attached to.
99445ad495SJason Gunthorpe * @device_feature: Optional, fill in the VFIO_DEVICE_FEATURE ioctl
100cba3345cSAlex Williamson */
101cba3345cSAlex Williamson struct vfio_device_ops {
102cba3345cSAlex Williamson char *name;
103cb9ff3f3SKevin Tian int (*init)(struct vfio_device *vdev);
104cb9ff3f3SKevin Tian void (*release)(struct vfio_device *vdev);
105a4d1f91dSJason Gunthorpe int (*bind_iommufd)(struct vfio_device *vdev,
106a4d1f91dSJason Gunthorpe struct iommufd_ctx *ictx, u32 *out_device_id);
107a4d1f91dSJason Gunthorpe void (*unbind_iommufd)(struct vfio_device *vdev);
108a4d1f91dSJason Gunthorpe int (*attach_ioas)(struct vfio_device *vdev, u32 *pt_id);
1099048c734SYi Liu void (*detach_ioas)(struct vfio_device *vdev);
1102fd585f4SJason Gunthorpe int (*open_device)(struct vfio_device *vdev);
1112fd585f4SJason Gunthorpe void (*close_device)(struct vfio_device *vdev);
1126df62c5bSJason Gunthorpe ssize_t (*read)(struct vfio_device *vdev, char __user *buf,
113cba3345cSAlex Williamson size_t count, loff_t *ppos);
1146df62c5bSJason Gunthorpe ssize_t (*write)(struct vfio_device *vdev, const char __user *buf,
115cba3345cSAlex Williamson size_t count, loff_t *size);
1166df62c5bSJason Gunthorpe long (*ioctl)(struct vfio_device *vdev, unsigned int cmd,
117cba3345cSAlex Williamson unsigned long arg);
1186df62c5bSJason Gunthorpe int (*mmap)(struct vfio_device *vdev, struct vm_area_struct *vma);
1196df62c5bSJason Gunthorpe void (*request)(struct vfio_device *vdev, unsigned int count);
1206df62c5bSJason Gunthorpe int (*match)(struct vfio_device *vdev, char *buf);
121ce4b4657SJason Gunthorpe void (*dma_unmap)(struct vfio_device *vdev, u64 iova, u64 length);
122445ad495SJason Gunthorpe int (*device_feature)(struct vfio_device *device, u32 flags,
123445ad495SJason Gunthorpe void __user *arg, size_t argsz);
1246e97eba8SYishai Hadas };
1256e97eba8SYishai Hadas
126a4d1f91dSJason Gunthorpe #if IS_ENABLED(CONFIG_IOMMUFD)
1279062ff40SYi Liu struct iommufd_ctx *vfio_iommufd_device_ictx(struct vfio_device *vdev);
1289062ff40SYi Liu int vfio_iommufd_get_dev_id(struct vfio_device *vdev, struct iommufd_ctx *ictx);
129a4d1f91dSJason Gunthorpe int vfio_iommufd_physical_bind(struct vfio_device *vdev,
130a4d1f91dSJason Gunthorpe struct iommufd_ctx *ictx, u32 *out_device_id);
131a4d1f91dSJason Gunthorpe void vfio_iommufd_physical_unbind(struct vfio_device *vdev);
132a4d1f91dSJason Gunthorpe int vfio_iommufd_physical_attach_ioas(struct vfio_device *vdev, u32 *pt_id);
1339048c734SYi Liu void vfio_iommufd_physical_detach_ioas(struct vfio_device *vdev);
1344741f2e9SJason Gunthorpe int vfio_iommufd_emulated_bind(struct vfio_device *vdev,
1354741f2e9SJason Gunthorpe struct iommufd_ctx *ictx, u32 *out_device_id);
1364741f2e9SJason Gunthorpe void vfio_iommufd_emulated_unbind(struct vfio_device *vdev);
1374741f2e9SJason Gunthorpe int vfio_iommufd_emulated_attach_ioas(struct vfio_device *vdev, u32 *pt_id);
1388cfa7186SYi Liu void vfio_iommufd_emulated_detach_ioas(struct vfio_device *vdev);
139a4d1f91dSJason Gunthorpe #else
1409062ff40SYi Liu static inline struct iommufd_ctx *
vfio_iommufd_device_ictx(struct vfio_device * vdev)1419062ff40SYi Liu vfio_iommufd_device_ictx(struct vfio_device *vdev)
1429062ff40SYi Liu {
1439062ff40SYi Liu return NULL;
1449062ff40SYi Liu }
1459062ff40SYi Liu
1469062ff40SYi Liu static inline int
vfio_iommufd_get_dev_id(struct vfio_device * vdev,struct iommufd_ctx * ictx)1479062ff40SYi Liu vfio_iommufd_get_dev_id(struct vfio_device *vdev, struct iommufd_ctx *ictx)
1489062ff40SYi Liu {
1499062ff40SYi Liu return VFIO_PCI_DEVID_NOT_OWNED;
1509062ff40SYi Liu }
1519062ff40SYi Liu
152a4d1f91dSJason Gunthorpe #define vfio_iommufd_physical_bind \
153a4d1f91dSJason Gunthorpe ((int (*)(struct vfio_device *vdev, struct iommufd_ctx *ictx, \
154a4d1f91dSJason Gunthorpe u32 *out_device_id)) NULL)
155a4d1f91dSJason Gunthorpe #define vfio_iommufd_physical_unbind \
156a4d1f91dSJason Gunthorpe ((void (*)(struct vfio_device *vdev)) NULL)
157a4d1f91dSJason Gunthorpe #define vfio_iommufd_physical_attach_ioas \
158a4d1f91dSJason Gunthorpe ((int (*)(struct vfio_device *vdev, u32 *pt_id)) NULL)
1599048c734SYi Liu #define vfio_iommufd_physical_detach_ioas \
1609048c734SYi Liu ((void (*)(struct vfio_device *vdev)) NULL)
1614741f2e9SJason Gunthorpe #define vfio_iommufd_emulated_bind \
1624741f2e9SJason Gunthorpe ((int (*)(struct vfio_device *vdev, struct iommufd_ctx *ictx, \
1634741f2e9SJason Gunthorpe u32 *out_device_id)) NULL)
1644741f2e9SJason Gunthorpe #define vfio_iommufd_emulated_unbind \
1654741f2e9SJason Gunthorpe ((void (*)(struct vfio_device *vdev)) NULL)
1664741f2e9SJason Gunthorpe #define vfio_iommufd_emulated_attach_ioas \
1674741f2e9SJason Gunthorpe ((int (*)(struct vfio_device *vdev, u32 *pt_id)) NULL)
1688cfa7186SYi Liu #define vfio_iommufd_emulated_detach_ioas \
1698cfa7186SYi Liu ((void (*)(struct vfio_device *vdev)) NULL)
170a4d1f91dSJason Gunthorpe #endif
171a4d1f91dSJason Gunthorpe
vfio_device_cdev_opened(struct vfio_device * device)172af949759SYi Liu static inline bool vfio_device_cdev_opened(struct vfio_device *device)
173af949759SYi Liu {
1745fcc2696SYi Liu return device->cdev_opened;
175af949759SYi Liu }
176af949759SYi Liu
1776e97eba8SYishai Hadas /**
17838e4614cSSimon Horman * struct vfio_migration_ops - VFIO bus device driver migration callbacks
17938e4614cSSimon Horman *
1806e97eba8SYishai Hadas * @migration_set_state: Optional callback to change the migration state for
1816e97eba8SYishai Hadas * devices that support migration. It's mandatory for
1826e97eba8SYishai Hadas * VFIO_DEVICE_FEATURE_MIGRATION migration support.
1836e97eba8SYishai Hadas * The returned FD is used for data transfer according to the FSM
1846e97eba8SYishai Hadas * definition. The driver is responsible to ensure that FD reaches end
1856e97eba8SYishai Hadas * of stream or error whenever the migration FSM leaves a data transfer
1866e97eba8SYishai Hadas * state or before close_device() returns.
1876e97eba8SYishai Hadas * @migration_get_state: Optional callback to get the migration state for
1886e97eba8SYishai Hadas * devices that support migration. It's mandatory for
1896e97eba8SYishai Hadas * VFIO_DEVICE_FEATURE_MIGRATION migration support.
1904e016f96SYishai Hadas * @migration_get_data_size: Optional callback to get the estimated data
1914e016f96SYishai Hadas * length that will be required to complete stop copy. It's mandatory for
1924e016f96SYishai Hadas * VFIO_DEVICE_FEATURE_MIGRATION migration support.
1936e97eba8SYishai Hadas */
1946e97eba8SYishai Hadas struct vfio_migration_ops {
195115dcec6SJason Gunthorpe struct file *(*migration_set_state)(
196115dcec6SJason Gunthorpe struct vfio_device *device,
197115dcec6SJason Gunthorpe enum vfio_device_mig_state new_state);
198115dcec6SJason Gunthorpe int (*migration_get_state)(struct vfio_device *device,
199115dcec6SJason Gunthorpe enum vfio_device_mig_state *curr_state);
2004e016f96SYishai Hadas int (*migration_get_data_size)(struct vfio_device *device,
2014e016f96SYishai Hadas unsigned long *stop_copy_length);
202cba3345cSAlex Williamson };
203cba3345cSAlex Williamson
204445ad495SJason Gunthorpe /**
20538e4614cSSimon Horman * struct vfio_log_ops - VFIO bus device driver logging callbacks
20638e4614cSSimon Horman *
20780c4b92aSYishai Hadas * @log_start: Optional callback to ask the device start DMA logging.
20880c4b92aSYishai Hadas * @log_stop: Optional callback to ask the device stop DMA logging.
20980c4b92aSYishai Hadas * @log_read_and_clear: Optional callback to ask the device read
21080c4b92aSYishai Hadas * and clear the dirty DMAs in some given range.
21180c4b92aSYishai Hadas *
21280c4b92aSYishai Hadas * The vfio core implementation of the DEVICE_FEATURE_DMA_LOGGING_ set
21380c4b92aSYishai Hadas * of features does not track logging state relative to the device,
21480c4b92aSYishai Hadas * therefore the device implementation of vfio_log_ops must handle
21580c4b92aSYishai Hadas * arbitrary user requests. This includes rejecting subsequent calls
21680c4b92aSYishai Hadas * to log_start without an intervening log_stop, as well as graceful
21780c4b92aSYishai Hadas * handling of log_stop and log_read_and_clear from invalid states.
21880c4b92aSYishai Hadas */
21980c4b92aSYishai Hadas struct vfio_log_ops {
22080c4b92aSYishai Hadas int (*log_start)(struct vfio_device *device,
22180c4b92aSYishai Hadas struct rb_root_cached *ranges, u32 nnodes, u64 *page_size);
22280c4b92aSYishai Hadas int (*log_stop)(struct vfio_device *device);
22380c4b92aSYishai Hadas int (*log_read_and_clear)(struct vfio_device *device,
22480c4b92aSYishai Hadas unsigned long iova, unsigned long length,
22580c4b92aSYishai Hadas struct iova_bitmap *dirty);
22680c4b92aSYishai Hadas };
22780c4b92aSYishai Hadas
22880c4b92aSYishai Hadas /**
229445ad495SJason Gunthorpe * vfio_check_feature - Validate user input for the VFIO_DEVICE_FEATURE ioctl
230445ad495SJason Gunthorpe * @flags: Arg from the device_feature op
231445ad495SJason Gunthorpe * @argsz: Arg from the device_feature op
232445ad495SJason Gunthorpe * @supported_ops: Combination of VFIO_DEVICE_FEATURE_GET and SET the driver
233445ad495SJason Gunthorpe * supports
234445ad495SJason Gunthorpe * @minsz: Minimum data size the driver accepts
235445ad495SJason Gunthorpe *
236445ad495SJason Gunthorpe * For use in a driver's device_feature op. Checks that the inputs to the
237445ad495SJason Gunthorpe * VFIO_DEVICE_FEATURE ioctl are correct for the driver's feature. Returns 1 if
238445ad495SJason Gunthorpe * the driver should execute the get or set, otherwise the relevant
239445ad495SJason Gunthorpe * value should be returned.
240445ad495SJason Gunthorpe */
vfio_check_feature(u32 flags,size_t argsz,u32 supported_ops,size_t minsz)241445ad495SJason Gunthorpe static inline int vfio_check_feature(u32 flags, size_t argsz, u32 supported_ops,
242445ad495SJason Gunthorpe size_t minsz)
243445ad495SJason Gunthorpe {
244445ad495SJason Gunthorpe if ((flags & (VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_SET)) &
245445ad495SJason Gunthorpe ~supported_ops)
246445ad495SJason Gunthorpe return -EINVAL;
247445ad495SJason Gunthorpe if (flags & VFIO_DEVICE_FEATURE_PROBE)
248445ad495SJason Gunthorpe return 0;
249445ad495SJason Gunthorpe /* Without PROBE one of GET or SET must be requested */
250445ad495SJason Gunthorpe if (!(flags & (VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_SET)))
251445ad495SJason Gunthorpe return -EINVAL;
252445ad495SJason Gunthorpe if (argsz < minsz)
253445ad495SJason Gunthorpe return -EINVAL;
254445ad495SJason Gunthorpe return 1;
255445ad495SJason Gunthorpe }
256445ad495SJason Gunthorpe
257cb9ff3f3SKevin Tian struct vfio_device *_vfio_alloc_device(size_t size, struct device *dev,
258cb9ff3f3SKevin Tian const struct vfio_device_ops *ops);
259cb9ff3f3SKevin Tian #define vfio_alloc_device(dev_struct, member, dev, ops) \
260cb9ff3f3SKevin Tian container_of(_vfio_alloc_device(sizeof(struct dev_struct) + \
261cb9ff3f3SKevin Tian BUILD_BUG_ON_ZERO(offsetof( \
262cb9ff3f3SKevin Tian struct dev_struct, member)), \
263cb9ff3f3SKevin Tian dev, ops), \
264cb9ff3f3SKevin Tian struct dev_struct, member)
265cb9ff3f3SKevin Tian
vfio_put_device(struct vfio_device * device)266cb9ff3f3SKevin Tian static inline void vfio_put_device(struct vfio_device *device)
267cb9ff3f3SKevin Tian {
2683c28a761SYi Liu put_device(&device->device);
269cb9ff3f3SKevin Tian }
270cb9ff3f3SKevin Tian
2710bfc6a4eSJason Gunthorpe int vfio_register_group_dev(struct vfio_device *device);
272c68ea0d0SChristoph Hellwig int vfio_register_emulated_iommu_dev(struct vfio_device *device);
2730bfc6a4eSJason Gunthorpe void vfio_unregister_group_dev(struct vfio_device *device);
274cba3345cSAlex Williamson
2752fd585f4SJason Gunthorpe int vfio_assign_device_set(struct vfio_device *device, void *set_id);
2765cd189e4SAnthony DeRossi unsigned int vfio_device_set_open_count(struct vfio_device_set *dev_set);
277a80e1de9SYi Liu struct vfio_device *
278a80e1de9SYi Liu vfio_find_device_in_devset(struct vfio_device_set *dev_set,
279a80e1de9SYi Liu struct device *dev);
2802fd585f4SJason Gunthorpe
281115dcec6SJason Gunthorpe int vfio_mig_get_next_state(struct vfio_device *device,
282115dcec6SJason Gunthorpe enum vfio_device_mig_state cur_fsm,
283115dcec6SJason Gunthorpe enum vfio_device_mig_state new_fsm,
284115dcec6SJason Gunthorpe enum vfio_device_mig_state *next_fsm);
285115dcec6SJason Gunthorpe
2869a4087faSBrett Creeley void vfio_combine_iova_ranges(struct rb_root_cached *root, u32 cur_nodes,
2879a4087faSBrett Creeley u32 req_nodes);
2889a4087faSBrett Creeley
2896cdd9782SAlexey Kardashevskiy /*
2906cdd9782SAlexey Kardashevskiy * External user API
2916cdd9782SAlexey Kardashevskiy */
292d1877e63SAlex Williamson struct iommu_group *vfio_file_iommu_group(struct file *file);
293fcda4d22SSean Christopherson
294fcda4d22SSean Christopherson #if IS_ENABLED(CONFIG_VFIO_GROUP)
2954b22ef04SJason Gunthorpe bool vfio_file_is_group(struct file *file);
296c1cce6d0SYi Liu bool vfio_file_has_dev(struct file *file, struct vfio_device *device);
297c1cce6d0SYi Liu #else
vfio_file_is_group(struct file * file)298c1cce6d0SYi Liu static inline bool vfio_file_is_group(struct file *file)
299c1cce6d0SYi Liu {
300c1cce6d0SYi Liu return false;
301c1cce6d0SYi Liu }
302c1cce6d0SYi Liu
vfio_file_has_dev(struct file * file,struct vfio_device * device)303c1cce6d0SYi Liu static inline bool vfio_file_has_dev(struct file *file, struct vfio_device *device)
304c1cce6d0SYi Liu {
305c1cce6d0SYi Liu return false;
306c1cce6d0SYi Liu }
307c1cce6d0SYi Liu #endif
308b1a59be8SYi Liu bool vfio_file_is_valid(struct file *file);
309d1877e63SAlex Williamson bool vfio_file_enforced_coherent(struct file *file);
310d1877e63SAlex Williamson void vfio_file_set_kvm(struct file *file, struct kvm *kvm);
3116cdd9782SAlexey Kardashevskiy
3122169037dSKirti Wankhede #define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long))
3132169037dSKirti Wankhede
31444abdd16SNicolin Chen int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova,
31534a255e6SNicolin Chen int npage, int prot, struct page **pages);
31644abdd16SNicolin Chen void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, int npage);
3178561aa4fSNicolin Chen int vfio_dma_rw(struct vfio_device *device, dma_addr_t iova,
3188d46c0ccSYan Zhao void *data, size_t len, bool write);
3198d46c0ccSYan Zhao
320d7a8d5edSAlex Williamson /*
321d7a8d5edSAlex Williamson * Sub-module helpers
322d7a8d5edSAlex Williamson */
323d7a8d5edSAlex Williamson struct vfio_info_cap {
324d7a8d5edSAlex Williamson struct vfio_info_cap_header *buf;
325d7a8d5edSAlex Williamson size_t size;
326d7a8d5edSAlex Williamson };
327d1877e63SAlex Williamson struct vfio_info_cap_header *vfio_info_cap_add(struct vfio_info_cap *caps,
328d1877e63SAlex Williamson size_t size, u16 id,
329d1877e63SAlex Williamson u16 version);
330d1877e63SAlex Williamson void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset);
331d7a8d5edSAlex Williamson
332d1877e63SAlex Williamson int vfio_info_add_capability(struct vfio_info_cap *caps,
333d1877e63SAlex Williamson struct vfio_info_cap_header *cap, size_t size);
334b3c0a866SKirti Wankhede
335d1877e63SAlex Williamson int vfio_set_irqs_validate_and_prepare(struct vfio_irq_set *hdr,
336c747f08aSKirti Wankhede int num_irqs, int max_irq_type,
337c747f08aSKirti Wankhede size_t *data_size);
338c747f08aSKirti Wankhede
3397e992d69SAntonios Motakis /*
3407e992d69SAntonios Motakis * IRQfd - generic
3417e992d69SAntonios Motakis */
3427e992d69SAntonios Motakis struct virqfd {
3437e992d69SAntonios Motakis void *opaque;
3447e992d69SAntonios Motakis struct eventfd_ctx *eventfd;
3457e992d69SAntonios Motakis int (*handler)(void *, void *);
3467e992d69SAntonios Motakis void (*thread)(void *, void *);
3477e992d69SAntonios Motakis void *data;
3487e992d69SAntonios Motakis struct work_struct inject;
349ac6424b9SIngo Molnar wait_queue_entry_t wait;
3507e992d69SAntonios Motakis poll_table pt;
3517e992d69SAntonios Motakis struct work_struct shutdown;
3522ee432d7SAlex Williamson struct work_struct flush_inject;
3537e992d69SAntonios Motakis struct virqfd **pvirqfd;
3547e992d69SAntonios Motakis };
3557e992d69SAntonios Motakis
356d1877e63SAlex Williamson int vfio_virqfd_enable(void *opaque, int (*handler)(void *, void *),
357d1877e63SAlex Williamson void (*thread)(void *, void *), void *data,
358d1877e63SAlex Williamson struct virqfd **pvirqfd, int fd);
359d1877e63SAlex Williamson void vfio_virqfd_disable(struct virqfd **pvirqfd);
3602ee432d7SAlex Williamson void vfio_virqfd_flush_thread(struct virqfd **pvirqfd);
3617e992d69SAntonios Motakis
362cba3345cSAlex Williamson #endif /* VFIO_H */
363