]> git.ipfire.org Git - thirdparty/qemu.git/blobdiff - linux-headers/linux/vfio.h
linux-headers: Update to Linux v6.6-rc1
[thirdparty/qemu.git] / linux-headers / linux / vfio.h
index 16db89071eabdea7166cbbe20c4dee3130360be6..acf72b4999fa75dfcd4c49426c9fdbc135251248 100644 (file)
@@ -217,6 +217,7 @@ struct vfio_device_info {
        __u32   num_regions;    /* Max region index + 1 */
        __u32   num_irqs;       /* Max IRQ index + 1 */
        __u32   cap_offset;     /* Offset within info struct of first cap */
+       __u32   pad;
 };
 #define VFIO_DEVICE_GET_INFO           _IO(VFIO_TYPE, VFIO_BASE + 7)
 
@@ -677,11 +678,60 @@ enum {
  * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 12,
  *                                           struct vfio_pci_hot_reset_info)
  *
+ * This command is used to query the affected devices in the hot reset for
+ * a given device.
+ *
+ * This command always reports the segment, bus, and devfn information for
+ * each affected device, and selectively reports the group_id or devid per
+ * the way how the calling device is opened.
+ *
+ *     - If the calling device is opened via the traditional group/container
+ *       API, group_id is reported.  User should check if it has owned all
+ *       the affected devices and provides a set of group fds to prove the
+ *       ownership in VFIO_DEVICE_PCI_HOT_RESET ioctl.
+ *
+ *     - If the calling device is opened as a cdev, devid is reported.
+ *       Flag VFIO_PCI_HOT_RESET_FLAG_DEV_ID is set to indicate this
+ *       data type.  All the affected devices should be represented in
+ *       the dev_set, ex. bound to a vfio driver, and also be owned by
+ *       this interface which is determined by the following conditions:
+ *       1) Has a valid devid within the iommufd_ctx of the calling device.
+ *          Ownership cannot be determined across separate iommufd_ctx and
+ *          the cdev calling conventions do not support a proof-of-ownership
+ *          model as provided in the legacy group interface.  In this case
+ *          valid devid with value greater than zero is provided in the return
+ *          structure.
+ *       2) Does not have a valid devid within the iommufd_ctx of the calling
+ *          device, but belongs to the same IOMMU group as the calling device
+ *          or another opened device that has a valid devid within the
+ *          iommufd_ctx of the calling device.  This provides implicit ownership
+ *          for devices within the same DMA isolation context.  In this case
+ *          the devid value of VFIO_PCI_DEVID_OWNED is provided in the return
+ *          structure.
+ *
+ *       A devid value of VFIO_PCI_DEVID_NOT_OWNED is provided in the return
+ *       structure for affected devices where device is NOT represented in the
+ *       dev_set or ownership is not available.  Such devices prevent the use
+ *       of VFIO_DEVICE_PCI_HOT_RESET ioctl outside of the proof-of-ownership
+ *       calling conventions (ie. via legacy group accessed devices).  Flag
+ *       VFIO_PCI_HOT_RESET_FLAG_DEV_ID_OWNED would be set when all the
+ *       affected devices are represented in the dev_set and also owned by
+ *       the user.  This flag is available only when
+ *       flag VFIO_PCI_HOT_RESET_FLAG_DEV_ID is set, otherwise reserved.
+ *       When set, user could invoke VFIO_DEVICE_PCI_HOT_RESET with a zero
+ *       length fd array on the calling device as the ownership is validated
+ *       by iommufd_ctx.
+ *
  * Return: 0 on success, -errno on failure:
  *     -enospc = insufficient buffer, -enodev = unsupported for device.
  */
 struct vfio_pci_dependent_device {
-       __u32   group_id;
+       union {
+               __u32   group_id;
+               __u32   devid;
+#define VFIO_PCI_DEVID_OWNED           0
+#define VFIO_PCI_DEVID_NOT_OWNED       -1
+       };
        __u16   segment;
        __u8    bus;
        __u8    devfn; /* Use PCI_SLOT/PCI_FUNC */
@@ -690,6 +740,8 @@ struct vfio_pci_dependent_device {
 struct vfio_pci_hot_reset_info {
        __u32   argsz;
        __u32   flags;
+#define VFIO_PCI_HOT_RESET_FLAG_DEV_ID         (1 << 0)
+#define VFIO_PCI_HOT_RESET_FLAG_DEV_ID_OWNED   (1 << 1)
        __u32   count;
        struct vfio_pci_dependent_device        devices[];
 };
@@ -700,6 +752,24 @@ struct vfio_pci_hot_reset_info {
  * VFIO_DEVICE_PCI_HOT_RESET - _IOW(VFIO_TYPE, VFIO_BASE + 13,
  *                                 struct vfio_pci_hot_reset)
  *
+ * A PCI hot reset results in either a bus or slot reset which may affect
+ * other devices sharing the bus/slot.  The calling user must have
+ * ownership of the full set of affected devices as determined by the
+ * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO ioctl.
+ *
+ * When called on a device file descriptor acquired through the vfio
+ * group interface, the user is required to provide proof of ownership
+ * of those affected devices via the group_fds array in struct
+ * vfio_pci_hot_reset.
+ *
+ * When called on a direct cdev opened vfio device, the flags field of
+ * struct vfio_pci_hot_reset_info reports the ownership status of the
+ * affected devices and this ioctl must be called with an empty group_fds
+ * array.  See above INFO ioctl definition for ownership requirements.
+ *
+ * Mixed usage of legacy groups and cdevs across the set of affected
+ * devices is not supported.
+ *
  * Return: 0 on success, -errno on failure.
  */
 struct vfio_pci_hot_reset {
@@ -828,6 +898,83 @@ struct vfio_device_feature {
 
 #define VFIO_DEVICE_FEATURE            _IO(VFIO_TYPE, VFIO_BASE + 17)
 
+/*
+ * VFIO_DEVICE_BIND_IOMMUFD - _IOR(VFIO_TYPE, VFIO_BASE + 18,
+ *                                struct vfio_device_bind_iommufd)
+ * @argsz:      User filled size of this data.
+ * @flags:      Must be 0.
+ * @iommufd:    iommufd to bind.
+ * @out_devid:  The device id generated by this bind. devid is a handle for
+ *              this device/iommufd bond and can be used in IOMMUFD commands.
+ *
+ * Bind a vfio_device to the specified iommufd.
+ *
+ * User is restricted from accessing the device before the binding operation
+ * is completed.  Only allowed on cdev fds.
+ *
+ * Unbind is automatically conducted when device fd is closed.
+ *
+ * Return: 0 on success, -errno on failure.
+ */
+struct vfio_device_bind_iommufd {
+       __u32           argsz;
+       __u32           flags;
+       __s32           iommufd;
+       __u32           out_devid;
+};
+
+#define VFIO_DEVICE_BIND_IOMMUFD       _IO(VFIO_TYPE, VFIO_BASE + 18)
+
+/*
+ * VFIO_DEVICE_ATTACH_IOMMUFD_PT - _IOW(VFIO_TYPE, VFIO_BASE + 19,
+ *                                     struct vfio_device_attach_iommufd_pt)
+ * @argsz:     User filled size of this data.
+ * @flags:     Must be 0.
+ * @pt_id:     Input the target id which can represent an ioas or a hwpt
+ *             allocated via iommufd subsystem.
+ *             Output the input ioas id or the attached hwpt id which could
+ *             be the specified hwpt itself or a hwpt automatically created
+ *             for the specified ioas by kernel during the attachment.
+ *
+ * Associate the device with an address space within the bound iommufd.
+ * Undo by VFIO_DEVICE_DETACH_IOMMUFD_PT or device fd close.  This is only
+ * allowed on cdev fds.
+ *
+ * If a vfio device is currently attached to a valid hw_pagetable, without doing
+ * a VFIO_DEVICE_DETACH_IOMMUFD_PT, a second VFIO_DEVICE_ATTACH_IOMMUFD_PT ioctl
+ * passing in another hw_pagetable (hwpt) id is allowed. This action, also known
+ * as a hw_pagetable replacement, will replace the device's currently attached
+ * hw_pagetable with a new hw_pagetable corresponding to the given pt_id.
+ *
+ * Return: 0 on success, -errno on failure.
+ */
+struct vfio_device_attach_iommufd_pt {
+       __u32   argsz;
+       __u32   flags;
+       __u32   pt_id;
+};
+
+#define VFIO_DEVICE_ATTACH_IOMMUFD_PT          _IO(VFIO_TYPE, VFIO_BASE + 19)
+
+/*
+ * VFIO_DEVICE_DETACH_IOMMUFD_PT - _IOW(VFIO_TYPE, VFIO_BASE + 20,
+ *                                     struct vfio_device_detach_iommufd_pt)
+ * @argsz:     User filled size of this data.
+ * @flags:     Must be 0.
+ *
+ * Remove the association of the device and its current associated address
+ * space.  After it, the device should be in a blocking DMA state.  This is only
+ * allowed on cdev fds.
+ *
+ * Return: 0 on success, -errno on failure.
+ */
+struct vfio_device_detach_iommufd_pt {
+       __u32   argsz;
+       __u32   flags;
+};
+
+#define VFIO_DEVICE_DETACH_IOMMUFD_PT          _IO(VFIO_TYPE, VFIO_BASE + 20)
+
 /*
  * Provide support for setting a PCI VF Token, which is used as a shared
  * secret between PF and VF drivers.  This feature may only be set on a
@@ -1304,6 +1451,7 @@ struct vfio_iommu_type1_info {
 #define VFIO_IOMMU_INFO_CAPS   (1 << 1)        /* Info supports caps */
        __u64   iova_pgsizes;   /* Bitmap of supported page sizes */
        __u32   cap_offset;     /* Offset within info struct of first cap */
+       __u32   pad;
 };
 
 /*