diff --git a/devicemodel/core/vmmapi.c b/devicemodel/core/vmmapi.c index 5365610f1..16944fac7 100644 --- a/devicemodel/core/vmmapi.c +++ b/devicemodel/core/vmmapi.c @@ -616,6 +616,18 @@ vm_unmap_ptdev_mmio(struct vmctx *ctx, int bus, int slot, int func, return ioctl(ctx->fd, IC_UNSET_MEMSEG, &memmap); } +int +vm_create_hv_vdev(struct vmctx *ctx, struct acrn_emul_dev *dev) +{ + return ioctl(ctx->fd, IC_CREATE_HV_VDEV, dev); +} + +int +vm_destroy_hv_vdev(struct vmctx *ctx, struct acrn_emul_dev *dev) +{ + return ioctl(ctx->fd, IC_DESTROY_HV_VDEV, dev); +} + int vm_set_ptdev_intx_info(struct vmctx *ctx, uint16_t virt_bdf, uint16_t phys_bdf, int virt_pin, int phys_pin, bool pic_pin) diff --git a/devicemodel/include/public/vhm_ioctl_defs.h b/devicemodel/include/public/vhm_ioctl_defs.h index dcf8d028d..99942b538 100644 --- a/devicemodel/include/public/vhm_ioctl_defs.h +++ b/devicemodel/include/public/vhm_ioctl_defs.h @@ -109,6 +109,8 @@ #define IC_DEASSIGN_PCIDEV _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x06) #define IC_ASSIGN_MMIODEV _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x07) #define IC_DEASSIGN_MMIODEV _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x08) +#define IC_CREATE_HV_VDEV _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x09) +#define IC_DESTROY_HV_VDEV _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x0A) /* Power management */ #define IC_ID_PM_BASE 0x60UL @@ -202,6 +204,49 @@ struct acrn_mmiodev { } __attribute__((aligned(8))); +/** + * @brief Info to create or destroy a virtual PCI or legacy device for a VM + * + * the parameter for HC_CREATE_VDEV or HC_DESTROY_VDEV hypercall + */ +struct acrn_emul_dev { + /* + * the identifier of the device, the low 32 bits represent the vendor + * id and device id of PCI device and the high 32 bits represent the + * device number of the legacy device + */ + union dev_id_info { + uint64_t value; + struct fields_info { + uint16_t vendor_id; + uint16_t device_id; + uint32_t legacy_device_number; + } fields; + } dev_id; + + /* + * the slot of the device, if the device is a PCI device, the slot + * represents BDF, otherwise it represents legacy device slot number + */ + uint32_t slot; + + /** reserved for extension */ + uint32_t reserved0; + + /** the IO resource address of the device, initialized by ACRN-DM. */ + uint32_t io_addr[6]; + + /** the IO resource size of the device, initialized by ACRN-DM. */ + uint32_t io_size[6]; + + /** the options for the virtual device, initialized by ACRN-DM. */ + uint8_t args[128]; + + /** reserved for extension */ + uint64_t reserved1[8]; + +} __attribute__((aligned(8))); + /** * @brief pass thru device irq data structure */ diff --git a/devicemodel/include/vmmapi.h b/devicemodel/include/vmmapi.h index 99dce96e4..059097e24 100644 --- a/devicemodel/include/vmmapi.h +++ b/devicemodel/include/vmmapi.h @@ -136,6 +136,8 @@ int vm_set_ptdev_intx_info(struct vmctx *ctx, uint16_t virt_bdf, uint16_t phys_bdf, int virt_pin, int phys_pin, bool pic_pin); int vm_reset_ptdev_intx_info(struct vmctx *ctx, uint16_t virt_bdf, uint16_t phys_bdf, int virt_pin, bool pic_pin); +int vm_create_hv_vdev(struct vmctx *ctx, struct acrn_emul_dev *dev); +int vm_destroy_hv_vdev(struct vmctx *ctx, struct acrn_emul_dev *dev); int acrn_parse_cpu_affinity(char *arg); int vm_create_vcpu(struct vmctx *ctx, uint16_t vcpu_id);