History

virt: acrn: Introduce interfaces for PCI device passthrough

PCI device passthrough enables an OS in a virtual machine to directly access a PCI device in the host. It promises almost the native performance, which is required in performance-critical scenarios of ACRN. HSM provides the following ioctls: - Assign - ACRN_IOCTL_ASSIGN_PCIDEV Pass data struct acrn_pcidev from userspace to the hypervisor, and inform the hypervisor to assign a PCI device to a User VM. - De-assign - ACRN_IOCTL_DEASSIGN_PCIDEV Pass data struct acrn_pcidev from userspace to the hypervisor, and inform the hypervisor to de-assign a PCI device from a User VM. - Set a interrupt of a passthrough device - ACRN_IOCTL_SET_PTDEV_INTR Pass data struct acrn_ptdev_irq from userspace to the hypervisor, and inform the hypervisor to map a INTx interrupt of passthrough device of User VM. - Reset passthrough device interrupt - ACRN_IOCTL_RESET_PTDEV_INTR Pass data struct acrn_ptdev_irq from userspace to the hypervisor, and inform the hypervisor to unmap a INTx interrupt of passthrough device of User VM.

Shuo Liu committed 5 years ago

Commit ce011e11 parent 3c4c3313 files · +165 −0Browse files

Showing the changes to include/uapi (1 of 3 files). Show all

Unified · Split

include/uapi/linux/acrn.h+61−0
@@ -365,6 +365,58 @@ struct acrn_vm_memmap { · 364 unmodified lines
365365 __u64 len;
366366 };
367367
368+/* Type of interrupt of a passthrough device */
369+#define ACRN_PTDEV_IRQ_INTX 0
370+#define ACRN_PTDEV_IRQ_MSI 1
371+#define ACRN_PTDEV_IRQ_MSIX 2
372+/**
373+ * struct acrn_ptdev_irq - Interrupt data of a passthrough device.
374+ * @type: Type (ACRN_PTDEV_IRQ_*)
375+ * @virt_bdf: Virtual Bus/Device/Function
376+ * @phys_bdf: Physical Bus/Device/Function
377+ * @intx: Info of interrupt
378+ * @intx.virt_pin: Virtual IOAPIC pin
379+ * @intx.phys_pin: Physical IOAPIC pin
380+ * @intx.is_pic_pin: Is PIC pin or not
381+ *
382+ * This structure will be passed to hypervisor directly.
383+ */
384+struct acrn_ptdev_irq {
385+ __u32 type;
386+ __u16 virt_bdf;
387+ __u16 phys_bdf;
388+
389+ struct {
390+ __u32 virt_pin;
391+ __u32 phys_pin;
392+ __u32 is_pic_pin;
393+ } intx;
394+};
395+
396+/* Type of PCI device assignment */
397+#define ACRN_PTDEV_QUIRK_ASSIGN (1U << 0)
398+
399+#define ACRN_PCI_NUM_BARS 6
400+/**
401+ * struct acrn_pcidev - Info for assigning or de-assigning a PCI device
402+ * @type: Type of the assignment
403+ * @virt_bdf: Virtual Bus/Device/Function
404+ * @phys_bdf: Physical Bus/Device/Function
405+ * @intr_line: PCI interrupt line
406+ * @intr_pin: PCI interrupt pin
407+ * @bar: PCI BARs.
408+ *
409+ * This structure will be passed to hypervisor directly.
410+ */
411+struct acrn_pcidev {
412+ __u32 type;
413+ __u16 virt_bdf;
414+ __u16 phys_bdf;
415+ __u8 intr_line;
416+ __u8 intr_pin;
417+ __u32 bar[ACRN_PCI_NUM_BARS];
418+};
419+
368420 /* The ioctl type, documented in ioctl-number.rst */
369421 #define ACRN_IOCTL_TYPE 0xA2
370422
@@ -400,4 +452,13 @@ struct acrn_vm_memmap { · 29 unmodified lines
400452 #define ACRN_IOCTL_UNSET_MEMSEG \
401453 _IOW(ACRN_IOCTL_TYPE, 0x42, struct acrn_vm_memmap)
402454
455+#define ACRN_IOCTL_SET_PTDEV_INTR \
456+ _IOW(ACRN_IOCTL_TYPE, 0x53, struct acrn_ptdev_irq)
457+#define ACRN_IOCTL_RESET_PTDEV_INTR \
458+ _IOW(ACRN_IOCTL_TYPE, 0x54, struct acrn_ptdev_irq)
459+#define ACRN_IOCTL_ASSIGN_PCIDEV \
460+ _IOW(ACRN_IOCTL_TYPE, 0x55, struct acrn_pcidev)
461+#define ACRN_IOCTL_DEASSIGN_PCIDEV \
462+ _IOW(ACRN_IOCTL_TYPE, 0x56, struct acrn_pcidev)
463+
403464 #endif /* _UAPI_ACRN_H */