From aa38ed5b69999c9c26a7d447d11296c6cea7a248 Mon Sep 17 00:00:00 2001 From: Li Fei1 Date: Sun, 19 Jan 2020 19:11:41 +0800 Subject: [PATCH] dm: vPCI: add assign/deassign PCI device IC APIs Add assign/deassign PCI device ioctl APIs assign a PCI device from SOS to post-launched VM or deassign a PCI device from post-launched VM to SOS. This patch is prepared for spliting passthrough PCI device from DM to HV. The old assign/deassign ptdev APIs will be discarded. Tracked-On: #4371 Signed-off-by: Li Fei1 Acked-by: Eddie Dong --- devicemodel/core/vmmapi.c | 12 ++++++++ devicemodel/include/public/vhm_ioctl_defs.h | 34 +++++++++++++++++++++ devicemodel/include/vmmapi.h | 2 ++ 3 files changed, 48 insertions(+) diff --git a/devicemodel/core/vmmapi.c b/devicemodel/core/vmmapi.c index 167654e66..cb3afb8d7 100644 --- a/devicemodel/core/vmmapi.c +++ b/devicemodel/core/vmmapi.c @@ -479,6 +479,18 @@ vm_unassign_ptdev(struct vmctx *ctx, int bus, int slot, int func) return ioctl(ctx->fd, IC_DEASSIGN_PTDEV, &bdf); } +int +vm_assign_pcidev(struct vmctx *ctx, struct acrn_assign_pcidev *pcidev) +{ + return ioctl(ctx->fd, IC_ASSIGN_PCIDEV, pcidev); +} + +int +vm_deassign_pcidev(struct vmctx *ctx, struct acrn_assign_pcidev *pcidev) +{ + return ioctl(ctx->fd, IC_DEASSIGN_PCIDEV, pcidev); +} + int vm_map_ptdev_mmio(struct vmctx *ctx, int bus, int slot, int func, vm_paddr_t gpa, size_t len, vm_paddr_t hpa) diff --git a/devicemodel/include/public/vhm_ioctl_defs.h b/devicemodel/include/public/vhm_ioctl_defs.h index 4ebfc3966..ca76859fb 100644 --- a/devicemodel/include/public/vhm_ioctl_defs.h +++ b/devicemodel/include/public/vhm_ioctl_defs.h @@ -105,6 +105,8 @@ #define IC_VM_PCI_MSIX_REMAP _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x02) #define IC_SET_PTDEV_INTR_INFO _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x03) #define IC_RESET_PTDEV_INTR_INFO _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x04) +#define IC_ASSIGN_PCIDEV _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x05) +#define IC_DEASSIGN_PCIDEV _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x06) /* Power management */ #define IC_ID_PM_BASE 0x60UL @@ -147,6 +149,38 @@ struct vm_memmap { uint32_t prot; /* RWX */ }; +/** + * @brief Info to assign or deassign PCI for a VM + * + */ +struct acrn_assign_pcidev { + /** reversed for externed compatibility */ + uint32_t rsvd1; + + /** virtual BDF# of the pass-through PCI device */ + uint16_t virt_bdf; + + /** physical BDF# of the pass-through PCI device */ + uint16_t phys_bdf; + + /** the PCI Interrupt Line, initialized by ACRN-DM, which is RO and + * ideally not used for pass-through MSI/MSI-x devices. + */ + uint8_t intr_line; + + /** the PCI Interrupt Pin, initialized by ACRN-DM, which is RO and + * ideally not used for pass-through MSI/MSI-x devices. + */ + uint8_t intr_pin; + + /** the base address of the PCI BAR, initialized by ACRN-DM. */ + uint32_t bar[6]; + + /** reserved for extension */ + uint32_t rsvd2[6]; + +} __attribute__((aligned(8))); + /** * @brief pass thru device irq data structure */ diff --git a/devicemodel/include/vmmapi.h b/devicemodel/include/vmmapi.h index ab42358a1..67cc4b5ad 100644 --- a/devicemodel/include/vmmapi.h +++ b/devicemodel/include/vmmapi.h @@ -125,6 +125,8 @@ int vm_lapic_msi(struct vmctx *ctx, uint64_t addr, uint64_t msg); int vm_set_gsi_irq(struct vmctx *ctx, int gsi, uint32_t operation); int vm_assign_ptdev(struct vmctx *ctx, int bus, int slot, int func); int vm_unassign_ptdev(struct vmctx *ctx, int bus, int slot, int func); +int vm_assign_pcidev(struct vmctx *ctx, struct acrn_assign_pcidev *pcidev); +int vm_deassign_pcidev(struct vmctx *ctx, struct acrn_assign_pcidev *pcidev); int vm_map_ptdev_mmio(struct vmctx *ctx, int bus, int slot, int func, vm_paddr_t gpa, size_t len, vm_paddr_t hpa); int vm_unmap_ptdev_mmio(struct vmctx *ctx, int bus, int slot, int func,