xref: /openbmc/linux/drivers/vfio/vfio.h (revision 67559900)
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 				     unsigned long *user_pfn,
54 				     int npage, int prot,
55 				     unsigned long *phys_pfn);
56 	int		(*unpin_pages)(void *iommu_data,
57 				       unsigned long *user_pfn, int npage);
58 	int		(*register_notifier)(void *iommu_data,
59 					     unsigned long *events,
60 					     struct notifier_block *nb);
61 	int		(*unregister_notifier)(void *iommu_data,
62 					       struct notifier_block *nb);
63 	int		(*dma_rw)(void *iommu_data, dma_addr_t user_iova,
64 				  void *data, size_t count, bool write);
65 	struct iommu_domain *(*group_iommu_domain)(void *iommu_data,
66 						   struct iommu_group *group);
67 	void		(*notify)(void *iommu_data,
68 				  enum vfio_iommu_notify_type event);
69 };
70 
71 int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops);
72 void vfio_unregister_iommu_driver(const struct vfio_iommu_driver_ops *ops);
73