Merge tag 'pm-5.15-rc1-3' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[linux-2.6-microblaze.git] / include / linux / vfio.h
index b7e18bd..b53a955 100644 (file)
 #include <linux/poll.h>
 #include <uapi/linux/vfio.h>
 
+/*
+ * VFIO devices can be placed in a set, this allows all devices to share this
+ * structure and the VFIO core will provide a lock that is held around
+ * open_device()/close_device() for all devices in the set.
+ */
+struct vfio_device_set {
+       void *set_id;
+       struct mutex lock;
+       struct list_head device_list;
+       unsigned int device_count;
+};
+
+struct vfio_device {
+       struct device *dev;
+       const struct vfio_device_ops *ops;
+       struct vfio_group *group;
+       struct vfio_device_set *dev_set;
+       struct list_head dev_set_list;
+
+       /* Members below here are private, not for driver use */
+       refcount_t refcount;
+       unsigned int open_count;
+       struct completion comp;
+       struct list_head group_next;
+};
+
 /**
  * struct vfio_device_ops - VFIO bus driver device callbacks
  *
- * @open: Called when userspace creates new file descriptor for device
- * @release: Called when userspace releases file descriptor for device
+ * @open_device: Called when the first file descriptor is opened for this device
+ * @close_device: Opposite of open_device
  * @read: Perform read(2) on device file descriptor
  * @write: Perform write(2) on device file descriptor
  * @ioctl: Perform ioctl(2) on device file descriptor, supporting VFIO_DEVICE_*
  */
 struct vfio_device_ops {
        char    *name;
-       int     (*open)(void *device_data);
-       void    (*release)(void *device_data);
-       ssize_t (*read)(void *device_data, char __user *buf,
+       int     (*open_device)(struct vfio_device *vdev);
+       void    (*close_device)(struct vfio_device *vdev);
+       ssize_t (*read)(struct vfio_device *vdev, char __user *buf,
                        size_t count, loff_t *ppos);
-       ssize_t (*write)(void *device_data, const char __user *buf,
+       ssize_t (*write)(struct vfio_device *vdev, const char __user *buf,
                         size_t count, loff_t *size);
-       long    (*ioctl)(void *device_data, unsigned int cmd,
+       long    (*ioctl)(struct vfio_device *vdev, unsigned int cmd,
                         unsigned long arg);
-       int     (*mmap)(void *device_data, struct vm_area_struct *vma);
-       void    (*request)(void *device_data, unsigned int count);
-       int     (*match)(void *device_data, char *buf);
+       int     (*mmap)(struct vfio_device *vdev, struct vm_area_struct *vma);
+       void    (*request)(struct vfio_device *vdev, unsigned int count);
+       int     (*match)(struct vfio_device *vdev, char *buf);
 };
 
 extern struct iommu_group *vfio_iommu_group_get(struct device *dev);
 extern void vfio_iommu_group_put(struct iommu_group *group, struct device *dev);
 
-extern int vfio_add_group_dev(struct device *dev,
-                             const struct vfio_device_ops *ops,
-                             void *device_data);
-
-extern void *vfio_del_group_dev(struct device *dev);
+void vfio_init_group_dev(struct vfio_device *device, struct device *dev,
+                        const struct vfio_device_ops *ops);
+void vfio_uninit_group_dev(struct vfio_device *device);
+int vfio_register_group_dev(struct vfio_device *device);
+void vfio_unregister_group_dev(struct vfio_device *device);
 extern struct vfio_device *vfio_device_get_from_dev(struct device *dev);
 extern void vfio_device_put(struct vfio_device *device);
-extern void *vfio_device_data(struct vfio_device *device);
+
+int vfio_assign_device_set(struct vfio_device *device, void *set_id);
 
 /* events for the backend driver notify callback */
 enum vfio_iommu_notify_type {