hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/include/linux/vfio.h
....@@ -1,12 +1,9 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * VFIO API definition
34 *
45 * Copyright (C) 2012 Red Hat, Inc. All rights reserved.
56 * Author: Alex Williamson <alex.williamson@redhat.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
107 */
118 #ifndef VFIO_H
129 #define VFIO_H
....@@ -17,6 +14,18 @@
1714 #include <linux/workqueue.h>
1815 #include <linux/poll.h>
1916 #include <uapi/linux/vfio.h>
17
+
18
+struct vfio_device {
19
+ struct device *dev;
20
+ const struct vfio_device_ops *ops;
21
+ struct vfio_group *group;
22
+
23
+ /* Members below here are private, not for driver use */
24
+ refcount_t refcount;
25
+ struct completion comp;
26
+ struct list_head group_next;
27
+ void *device_data;
28
+};
2029
2130 /**
2231 * struct vfio_device_ops - VFIO bus driver device callbacks
....@@ -29,6 +38,9 @@
2938 * operations documented below
3039 * @mmap: Perform mmap(2) on a region of the device file descriptor
3140 * @request: Request for the bus driver to release the device
41
+ * @match: Optional device name match callback (return: 0 for no-match, >0 for
42
+ * match, -errno for abort (ex. match with insufficient or incorrect
43
+ * additional args)
3244 */
3345 struct vfio_device_ops {
3446 char *name;
....@@ -42,16 +54,21 @@
4254 unsigned long arg);
4355 int (*mmap)(void *device_data, struct vm_area_struct *vma);
4456 void (*request)(void *device_data, unsigned int count);
57
+ int (*match)(void *device_data, char *buf);
4558 };
4659
4760 extern struct iommu_group *vfio_iommu_group_get(struct device *dev);
4861 extern void vfio_iommu_group_put(struct iommu_group *group, struct device *dev);
4962
63
+void vfio_init_group_dev(struct vfio_device *device, struct device *dev,
64
+ const struct vfio_device_ops *ops, void *device_data);
65
+int vfio_register_group_dev(struct vfio_device *device);
5066 extern int vfio_add_group_dev(struct device *dev,
5167 const struct vfio_device_ops *ops,
5268 void *device_data);
5369
5470 extern void *vfio_del_group_dev(struct device *dev);
71
+void vfio_unregister_group_dev(struct vfio_device *device);
5572 extern struct vfio_device *vfio_device_get_from_dev(struct device *dev);
5673 extern void vfio_device_put(struct vfio_device *device);
5774 extern void *vfio_device_data(struct vfio_device *device);
....@@ -75,7 +92,9 @@
7592 struct iommu_group *group);
7693 void (*detach_group)(void *iommu_data,
7794 struct iommu_group *group);
78
- int (*pin_pages)(void *iommu_data, unsigned long *user_pfn,
95
+ int (*pin_pages)(void *iommu_data,
96
+ struct iommu_group *group,
97
+ unsigned long *user_pfn,
7998 int npage, int prot,
8099 unsigned long *phys_pfn);
81100 int (*unpin_pages)(void *iommu_data,
....@@ -85,6 +104,8 @@
85104 struct notifier_block *nb);
86105 int (*unregister_notifier)(void *iommu_data,
87106 struct notifier_block *nb);
107
+ int (*dma_rw)(void *iommu_data, dma_addr_t user_iova,
108
+ void *data, size_t count, bool write);
88109 };
89110
90111 extern int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops);
....@@ -97,6 +118,8 @@
97118 */
98119 extern struct vfio_group *vfio_group_get_external_user(struct file *filep);
99120 extern void vfio_group_put_external_user(struct vfio_group *group);
121
+extern struct vfio_group *vfio_group_get_external_user_from_dev(struct device
122
+ *dev);
100123 extern bool vfio_external_group_match_file(struct vfio_group *group,
101124 struct file *filep);
102125 extern int vfio_external_user_iommu_id(struct vfio_group *group);
....@@ -110,6 +133,15 @@
110133 extern int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn,
111134 int npage);
112135
136
+extern int vfio_group_pin_pages(struct vfio_group *group,
137
+ unsigned long *user_iova_pfn, int npage,
138
+ int prot, unsigned long *phys_pfn);
139
+extern int vfio_group_unpin_pages(struct vfio_group *group,
140
+ unsigned long *user_iova_pfn, int npage);
141
+
142
+extern int vfio_dma_rw(struct vfio_group *group, dma_addr_t user_iova,
143
+ void *data, size_t len, bool write);
144
+
113145 /* each type has independent events */
114146 enum vfio_notify_type {
115147 VFIO_IOMMU_NOTIFY = 0,