xref: /openbmc/linux/drivers/vfio/vfio.h (revision a790cc3a)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2012 Red Hat, Inc.  All rights reserved.
4  *     Author: Alex Williamson <alex.williamson@redhat.com>
5  */
6 
7 enum vfio_group_type {
8 	/*
9 	 * Physical device with IOMMU backing.
10 	 */
11 	VFIO_IOMMU,
12 
13 	/*
14 	 * Virtual device without IOMMU backing. The VFIO core fakes up an
15 	 * iommu_group as the iommu_group sysfs interface is part of the
16 	 * userspace ABI.  The user of these devices must not be able to
17 	 * directly trigger unmediated DMA.
18 	 */
19 	VFIO_EMULATED_IOMMU,
20 
21 	/*
22 	 * Physical device without IOMMU backing. The VFIO core fakes up an
23 	 * iommu_group as the iommu_group sysfs interface is part of the
24 	 * userspace ABI.  Users can trigger unmediated DMA by the device,
25 	 * usage is highly dangerous, requires an explicit opt-in and will
26 	 * taint the kernel.
27 	 */
28 	VFIO_NO_IOMMU,
29 };
30 
31 /* events for the backend driver notify callback */
32 enum vfio_iommu_notify_type {
33 	VFIO_IOMMU_CONTAINER_CLOSE = 0,
34 };
35 
36 /**
37  * struct vfio_iommu_driver_ops - VFIO IOMMU driver callbacks
38  */
39 struct vfio_iommu_driver_ops {
40 	char		*name;
41 	struct module	*owner;
42 	void		*(*open)(unsigned long arg);
43 	void		(*release)(void *iommu_data);
44 	long		(*ioctl)(void *iommu_data, unsigned int cmd,
45 				 unsigned long arg);
46 	int		(*attach_group)(void *iommu_data,
47 					struct iommu_group *group,
48 					enum vfio_group_type);
49 	void		(*detach_group)(void *iommu_data,
50 					struct iommu_group *group);
51 	int		(*pin_pages)(void *iommu_data,
52 				     struct iommu_group *group,
53 				     dma_addr_t user_iova,
54 				     int npage, int prot,
55 				     struct page **pages);
56 	void		(*unpin_pages)(void *iommu_data,
57 				       dma_addr_t user_iova, int npage);
58 	void		(*register_device)(void *iommu_data,
59 					   struct vfio_device *vdev);
60 	void		(*unregister_device)(void *iommu_data,
61 					     struct vfio_device *vdev);
62 	int		(*dma_rw)(void *iommu_data, dma_addr_t user_iova,
63 				  void *data, size_t count, bool write);
64 	struct iommu_domain *(*group_iommu_domain)(void *iommu_data,
65 						   struct iommu_group *group);
66 	void		(*notify)(void *iommu_data,
67 				  enum vfio_iommu_notify_type event);
68 };
69 
70 int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops);
71 void vfio_unregister_iommu_driver(const struct vfio_iommu_driver_ops *ops);
72