From 98c80d75b81fdd770a23b0e6e9e5c3fff1b9cfc5 Mon Sep 17 00:00:00 2001 From: Shuo A Liu Date: Wed, 7 Jul 2021 17:23:40 +0800 Subject: [PATCH] hv: dm: Use new virtual device management ioctls IC_ADD_HV_VDEV -> ACRN_IOCTL_CREATE_VDEV IC_REMOVE_HV_VDEV -> ACRN_IOCTL_DESTROY_VDEV struct acrn_emul_dev -> struct acrn_vdev Also, move struct acrn_vdev to acrn_common.h as this structure is used by both DM and HV. Tracked-On: #6282 Signed-off-by: Shuo A Liu --- devicemodel/core/vmmapi.c | 8 ++-- devicemodel/hw/pci/ivshmem.c | 12 ++--- devicemodel/hw/pci/ptm.c | 6 +-- devicemodel/hw/pci/uart.c | 12 ++--- devicemodel/include/public/hsm_ioctl_defs.h | 50 ++------------------- devicemodel/include/vmmapi.h | 4 +- hypervisor/common/hypercall.c | 14 +++--- hypervisor/dm/vpci/ivshmem.c | 2 +- hypervisor/dm/vpci/vmcs9900.c | 2 +- hypervisor/dm/vpci/vroot_port.c | 4 +- hypervisor/include/common/hypercall.h | 4 +- hypervisor/include/dm/ivshmem.h | 2 +- hypervisor/include/dm/vmcs9900.h | 2 +- hypervisor/include/dm/vroot_port.h | 2 +- hypervisor/include/public/acrn_common.h | 36 +++++++++++++++ hypervisor/include/public/acrn_hv_defs.h | 43 ------------------ 16 files changed, 77 insertions(+), 126 deletions(-) diff --git a/devicemodel/core/vmmapi.c b/devicemodel/core/vmmapi.c index ce11cf1e5..cccc64396 100644 --- a/devicemodel/core/vmmapi.c +++ b/devicemodel/core/vmmapi.c @@ -596,15 +596,15 @@ vm_unmap_ptdev_mmio(struct vmctx *ctx, int bus, int slot, int func, } int -vm_add_hv_vdev(struct vmctx *ctx, struct acrn_emul_dev *dev) +vm_add_hv_vdev(struct vmctx *ctx, struct acrn_vdev *dev) { - return ioctl(ctx->fd, IC_ADD_HV_VDEV, dev); + return ioctl(ctx->fd, ACRN_IOCTL_CREATE_VDEV, dev); } int -vm_remove_hv_vdev(struct vmctx *ctx, struct acrn_emul_dev *dev) +vm_remove_hv_vdev(struct vmctx *ctx, struct acrn_vdev *dev) { - return ioctl(ctx->fd, IC_REMOVE_HV_VDEV, dev); + return ioctl(ctx->fd, ACRN_IOCTL_DESTROY_VDEV, dev); } int diff --git a/devicemodel/hw/pci/ivshmem.c b/devicemodel/hw/pci/ivshmem.c index e832d0d75..0ac0d9eb7 100644 --- a/devicemodel/hw/pci/ivshmem.c +++ b/devicemodel/hw/pci/ivshmem.c @@ -147,11 +147,11 @@ static int create_ivshmem_from_hv(struct vmctx *ctx, struct pci_vdev *vdev, const char *shm_name, uint32_t shm_size) { - struct acrn_emul_dev dev = {}; + struct acrn_vdev dev = {}; uint64_t addr = 0; - dev.dev_id.fields.vendor_id = IVSHMEM_VENDOR_ID; - dev.dev_id.fields.device_id = IVSHMEM_DEVICE_ID; + dev.id.fields.vendor = IVSHMEM_VENDOR_ID; + dev.id.fields.device = IVSHMEM_DEVICE_ID; dev.slot = PCI_BDF(vdev->bus, vdev->slot, vdev->func); dev.io_addr[IVSHMEM_MMIO_BAR] = pci_get_cfgdata32(vdev, PCIR_BAR(IVSHMEM_MMIO_BAR)); @@ -347,10 +347,10 @@ static void destroy_ivshmem_from_hv(struct vmctx *ctx, struct pci_vdev *vdev) { - struct acrn_emul_dev emul_dev = {}; + struct acrn_vdev emul_dev = {}; - emul_dev.dev_id.fields.vendor_id = IVSHMEM_VENDOR_ID; - emul_dev.dev_id.fields.device_id = IVSHMEM_DEVICE_ID; + emul_dev.id.fields.vendor = IVSHMEM_VENDOR_ID; + emul_dev.id.fields.device = IVSHMEM_DEVICE_ID; emul_dev.slot = PCI_BDF(vdev->bus, vdev->slot, vdev->func); vm_remove_hv_vdev(ctx, &emul_dev); } diff --git a/devicemodel/hw/pci/ptm.c b/devicemodel/hw/pci/ptm.c index 199ad0db7..d628bd9fe 100644 --- a/devicemodel/hw/pci/ptm.c +++ b/devicemodel/hw/pci/ptm.c @@ -69,11 +69,11 @@ add_vroot_port(struct vmctx *ctx, struct passthru_dev *ptdev, struct pci_device int offset = 0; uint32_t dev_cap = 0; - struct acrn_emul_dev rp_vdev = {}; + struct acrn_vdev rp_vdev = {}; struct vrp_config *rp_priv = (struct vrp_config *)&rp_vdev.args; - rp_vdev.dev_id.fields.vendor_id = PTM_ROOT_PORT_VENDOR; - rp_vdev.dev_id.fields.device_id = PTM_ROOT_PORT_DEVICE; + rp_vdev.id.fields.vendor = PTM_ROOT_PORT_VENDOR; + rp_vdev.id.fields.device = PTM_ROOT_PORT_DEVICE; // virtual root port takes bdf from its downstream device rp_vdev.slot = PCI_BDF(ptdev->dev->bus, ptdev->dev->slot, ptdev->dev->func); diff --git a/devicemodel/hw/pci/uart.c b/devicemodel/hw/pci/uart.c index 2b4929041..cb649577a 100644 --- a/devicemodel/hw/pci/uart.c +++ b/devicemodel/hw/pci/uart.c @@ -89,7 +89,7 @@ pci_uart_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) char *tmp, *val = NULL; bool is_hv_land = false; uint32_t vuart_idx; - struct acrn_emul_dev vdev = {}; + struct acrn_vdev vdev = {}; int32_t err = 0; if (opts != NULL) { @@ -116,8 +116,8 @@ pci_uart_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) pci_emul_alloc_bar(dev, 0, PCIBAR_MEM32, 256); pci_emul_alloc_bar(dev, 1, PCIBAR_MEM32, PAGE_SIZE); dev->arg = NULL; - vdev.dev_id.fields.vendor_id = COM_VENDOR; - vdev.dev_id.fields.device_id = COM_DEV; + vdev.id.fields.vendor = COM_VENDOR; + vdev.id.fields.device = COM_DEV; vdev.slot = PCI_BDF(dev->bus, dev->slot, dev->func); vdev.io_addr[0] = pci_get_cfgdata32(dev, PCIR_BAR(0)); vdev.io_addr[1] = pci_get_cfgdata32(dev, PCIR_BAR(1)); @@ -150,11 +150,11 @@ static void pci_uart_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts) { struct uart_vdev *uart = (struct uart_vdev *)dev->arg; - struct acrn_emul_dev emul_dev = {}; + struct acrn_vdev emul_dev = {}; if (uart == NULL) { - emul_dev.dev_id.fields.vendor_id = COM_VENDOR; - emul_dev.dev_id.fields.device_id = COM_DEV; + emul_dev.id.fields.vendor = COM_VENDOR; + emul_dev.id.fields.device = COM_DEV; emul_dev.slot = PCI_BDF(dev->bus, dev->slot, dev->func); vm_remove_hv_vdev(ctx, &emul_dev); return; diff --git a/devicemodel/include/public/hsm_ioctl_defs.h b/devicemodel/include/public/hsm_ioctl_defs.h index 6ac14713e..b2f1f86bc 100644 --- a/devicemodel/include/public/hsm_ioctl_defs.h +++ b/devicemodel/include/public/hsm_ioctl_defs.h @@ -112,7 +112,6 @@ _IOW(ACRN_IOCTL_TYPE, 0x42, struct acrn_vm_memmap) /* PCI assignment*/ -#define IC_ID_PCI_BASE 0x50UL #define ACRN_IOCTL_SET_PTDEV_INTR \ _IOW(ACRN_IOCTL_TYPE, 0x53, struct acrn_ptdev_irq) #define ACRN_IOCTL_RESET_PTDEV_INTR \ @@ -125,8 +124,10 @@ _IOW(ACRN_IOCTL_TYPE, 0x57, struct acrn_mmiodev) #define ACRN_IOCTL_DEASSIGN_MMIODEV \ _IOW(ACRN_IOCTL_TYPE, 0x58, struct acrn_mmiodev) -#define IC_ADD_HV_VDEV _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x09) -#define IC_REMOVE_HV_VDEV _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x0A) +#define ACRN_IOCTL_CREATE_VDEV \ + _IOW(ACRN_IOCTL_TYPE, 0x59, struct acrn_vdev) +#define ACRN_IOCTL_DESTROY_VDEV \ + _IOW(ACRN_IOCTL_TYPE, 0x5A, struct acrn_vdev) /* Power management */ #define IC_ID_PM_BASE 0x60UL @@ -182,49 +183,6 @@ struct acrn_vm_memmap { __u64 len; }; -/** - * @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))); - /* Type of interrupt of a passthrough device */ #define ACRN_PTDEV_IRQ_INTX 0 #define ACRN_PTDEV_IRQ_MSI 1 diff --git a/devicemodel/include/vmmapi.h b/devicemodel/include/vmmapi.h index c5305c830..c8dab4f52 100644 --- a/devicemodel/include/vmmapi.h +++ b/devicemodel/include/vmmapi.h @@ -137,8 +137,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_add_hv_vdev(struct vmctx *ctx, struct acrn_emul_dev *dev); -int vm_remove_hv_vdev(struct vmctx *ctx, struct acrn_emul_dev *dev); +int vm_add_hv_vdev(struct vmctx *ctx, struct acrn_vdev *dev); +int vm_remove_hv_vdev(struct vmctx *ctx, struct acrn_vdev *dev); int acrn_parse_cpu_affinity(char *arg); uint64_t vm_get_cpu_affinity_dm(void); diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index 8f9c6c1f3..71c97f65f 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -30,7 +30,7 @@ #define DBG_LEVEL_HYCALL 6U -typedef int32_t (*emul_dev_create) (struct acrn_vm *vm, struct acrn_emul_dev *dev); +typedef int32_t (*emul_dev_create) (struct acrn_vm *vm, struct acrn_vdev *dev); typedef int32_t (*emul_dev_destroy) (struct pci_vdev *vdev); struct emul_dev_ops { /* @@ -1241,13 +1241,13 @@ int32_t hcall_set_callback_vector(__unused struct acrn_vcpu *vcpu, __unused stru /* * @pre dev != NULL */ -static struct emul_dev_ops *find_emul_dev_ops(struct acrn_emul_dev *dev) +static struct emul_dev_ops *find_emul_dev_ops(struct acrn_vdev *dev) { struct emul_dev_ops *op = NULL; uint32_t i; for (i = 0U; i < ARRAY_SIZE(emul_dev_ops_tbl); i++) { - if (emul_dev_ops_tbl[i].dev_id == dev->dev_id.value) { + if (emul_dev_ops_tbl[i].dev_id == dev->id.value) { op = &emul_dev_ops_tbl[i]; break; } @@ -1261,7 +1261,7 @@ static struct emul_dev_ops *find_emul_dev_ops(struct acrn_emul_dev *dev) * @param vcpu Pointer to vCPU that initiates the hypercall * @param target_vm Pointer to target VM data structure * @param param guest physical address. This gpa points to data structure of - * acrn_emul_dev including information about PCI or legacy devices + * acrn_vdev including information about PCI or legacy devices * * @pre is_sos_vm(vcpu->vm) * @return 0 on success, non-zero on error. @@ -1270,7 +1270,7 @@ int32_t hcall_add_vdev(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm, __unus { struct acrn_vm *vm = vcpu->vm; int32_t ret = -EINVAL; - struct acrn_emul_dev dev; + struct acrn_vdev dev; struct emul_dev_ops *op; /* We should only create a device to a post-launched VM at creating time for safety, not runtime or other cases*/ @@ -1293,7 +1293,7 @@ int32_t hcall_add_vdev(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm, __unus * @param vcpu Pointer to vCPU that initiates the hypercall * @param target_vm Pointer to target VM data structure * @param param guest physical address. This gpa points to data structure of - * acrn_emul_dev including information about PCI or legacy devices + * acrn_vdev including information about PCI or legacy devices * * @pre is_sos_vm(vcpu->vm) * @return 0 on success, non-zero on error. @@ -1302,7 +1302,7 @@ int32_t hcall_remove_vdev(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm, __u { struct acrn_vm *vm = vcpu->vm; int32_t ret = -EINVAL; - struct acrn_emul_dev dev; + struct acrn_vdev dev; struct pci_vdev *vdev; struct emul_dev_ops *op; union pci_bdf bdf; diff --git a/hypervisor/dm/vpci/ivshmem.c b/hypervisor/dm/vpci/ivshmem.c index c93021cb7..7bacf1aa2 100644 --- a/hypervisor/dm/vpci/ivshmem.c +++ b/hypervisor/dm/vpci/ivshmem.c @@ -361,7 +361,7 @@ static void deinit_ivshmem_vdev(struct pci_vdev *vdev) * @pre vm != NULL * @pre dev != NULL */ -int32_t create_ivshmem_vdev(struct acrn_vm *vm, struct acrn_emul_dev *dev) +int32_t create_ivshmem_vdev(struct acrn_vm *vm, struct acrn_vdev *dev) { uint32_t i; struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id); diff --git a/hypervisor/dm/vpci/vmcs9900.c b/hypervisor/dm/vpci/vmcs9900.c index 55a5293aa..857ea9b91 100644 --- a/hypervisor/dm/vpci/vmcs9900.c +++ b/hypervisor/dm/vpci/vmcs9900.c @@ -163,7 +163,7 @@ const struct pci_vdev_ops vmcs9900_ops = { .read_vdev_cfg = read_vmcs9900_cfg, }; -int32_t create_vmcs9900_vdev(struct acrn_vm *vm, struct acrn_emul_dev *dev) +int32_t create_vmcs9900_vdev(struct acrn_vm *vm, struct acrn_vdev *dev) { uint32_t i; struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id); diff --git a/hypervisor/dm/vpci/vroot_port.c b/hypervisor/dm/vpci/vroot_port.c index fa73884a7..e66e673a6 100644 --- a/hypervisor/dm/vpci/vroot_port.c +++ b/hypervisor/dm/vpci/vroot_port.c @@ -114,7 +114,7 @@ static void init_ptm(struct pci_vdev *vdev, struct vrp_config *vrp_config) pci_vdev_write_vcfg(vdev, PCIR_SUBBUS_1, 1U, vrp_config->subordinate_bus); } -int32_t create_vrp(struct acrn_vm *vm, struct acrn_emul_dev *dev) +int32_t create_vrp(struct acrn_vm *vm, struct acrn_vdev *dev) { struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id); struct acrn_vm_pci_dev_config *dev_config = NULL; @@ -128,7 +128,7 @@ int32_t create_vrp(struct acrn_vm *vm, struct acrn_emul_dev *dev) pr_acrnlog("%s: virtual root port phy_bdf=0x%x, vbdf=0x%x, vendor_id=0x%x, dev_id=0x%x,\ primary_bus=0x%x, secondary_bus=0x%x, sub_bus=0x%x.\n", __func__, vrp_config->phy_bdf, dev->slot, - dev->dev_id.fields.vendor_id, dev->dev_id.fields.device_id, + dev->id.fields.vendor, dev->id.fields.device, vrp_config->primary_bus, vrp_config->secondary_bus, vrp_config->subordinate_bus); for (i = 0U; i < vm_config->pci_dev_num; i++) { diff --git a/hypervisor/include/common/hypercall.h b/hypervisor/include/common/hypercall.h index 7719dc42f..8e391a581 100644 --- a/hypervisor/include/common/hypercall.h +++ b/hypervisor/include/common/hypercall.h @@ -340,7 +340,7 @@ int32_t hcall_deassign_mmiodev(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm * @param target_vm Pointer to target VM data structure * @param param1 not used * @param param2 guest physical address. This gpa points to data structure of - * acrn_emul_dev including information about PCI or legacy devices + * acrn_vdev including information about PCI or legacy devices * * @pre is_sos_vm(vcpu->vm) * @return 0 on success, non-zero on error. @@ -354,7 +354,7 @@ int32_t hcall_add_vdev(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm, uint64 * @param target_vm Pointer to target VM data structure * @param param1 not used * @param param2 guest physical address. This gpa points to data structure of - * acrn_emul_dev including information about PCI or legacy devices + * acrn_vdev including information about PCI or legacy devices * * @pre is_sos_vm(vcpu->vm) * @return 0 on success, non-zero on error. diff --git a/hypervisor/include/dm/ivshmem.h b/hypervisor/include/dm/ivshmem.h index 17ada7e53..fe8e39066 100644 --- a/hypervisor/include/dm/ivshmem.h +++ b/hypervisor/include/dm/ivshmem.h @@ -37,7 +37,7 @@ extern const struct pci_vdev_ops vpci_ivshmem_ops; */ void init_ivshmem_shared_memory(void); -int32_t create_ivshmem_vdev(struct acrn_vm *vm, struct acrn_emul_dev *dev); +int32_t create_ivshmem_vdev(struct acrn_vm *vm, struct acrn_vdev *dev); int32_t destroy_ivshmem_vdev(struct pci_vdev *vdev); #endif /* CONFIG_IVSHMEM_ENABLED */ diff --git a/hypervisor/include/dm/vmcs9900.h b/hypervisor/include/dm/vmcs9900.h index 1ee3118a2..44a261930 100644 --- a/hypervisor/include/dm/vmcs9900.h +++ b/hypervisor/include/dm/vmcs9900.h @@ -12,7 +12,7 @@ extern const struct pci_vdev_ops vmcs9900_ops; void trigger_vmcs9900_msix(struct pci_vdev *vdev); -int32_t create_vmcs9900_vdev(struct acrn_vm *vm, struct acrn_emul_dev *dev); +int32_t create_vmcs9900_vdev(struct acrn_vm *vm, struct acrn_vdev *dev); int32_t destroy_vmcs9900_vdev(struct pci_vdev *vdev); #endif diff --git a/hypervisor/include/dm/vroot_port.h b/hypervisor/include/dm/vroot_port.h index 034af20db..c067eaa7f 100644 --- a/hypervisor/include/dm/vroot_port.h +++ b/hypervisor/include/dm/vroot_port.h @@ -15,7 +15,7 @@ extern const struct pci_vdev_ops vrp_ops; -int32_t create_vrp(struct acrn_vm *vm, struct acrn_emul_dev *dev); +int32_t create_vrp(struct acrn_vm *vm, struct acrn_vdev *dev); int32_t destroy_vrp(struct pci_vdev *vdev); #endif diff --git a/hypervisor/include/public/acrn_common.h b/hypervisor/include/public/acrn_common.h index 825087af4..83676884f 100644 --- a/hypervisor/include/public/acrn_common.h +++ b/hypervisor/include/public/acrn_common.h @@ -750,6 +750,42 @@ struct acrn_mmiodev { uint64_t size; } __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_vdev { + /* + * 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 { + uint64_t value; + struct { + uint16_t vendor; + uint16_t device; + uint32_t legacy_id; + } fields; + } id; + + /* + * the slot of the device, if the device is a PCI device, the slot + * represents BDF, otherwise it represents legacy device slot number + */ + uint64_t slot; + + /** the IO resource address of the device, initialized by ACRN-DM. */ + uint32_t io_addr[ACRN_PCI_NUM_BARS]; + + /** the IO resource size of the device, initialized by ACRN-DM. */ + uint32_t io_size[ACRN_PCI_NUM_BARS]; + + /** the options for the virtual device, initialized by ACRN-DM. */ + uint8_t args[128]; +}; + /** * @} */ diff --git a/hypervisor/include/public/acrn_hv_defs.h b/hypervisor/include/public/acrn_hv_defs.h index 5e43196c5..d07217311 100644 --- a/hypervisor/include/public/acrn_hv_defs.h +++ b/hypervisor/include/public/acrn_hv_defs.h @@ -271,49 +271,6 @@ struct hc_ptdev_irq { } __aligned(8); -/** - * @brief Info to create or destroy a virtual PCI or legacy device for a VM - * - * the parameter for HC_ADD_VDEV or HC_REMOVE_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))); - /** * Hypervisor api version info, return it for HC_GET_API_VERSION hypercall */