From 4c8e60f1d053b6500b321d688bf956f586ac0c24 Mon Sep 17 00:00:00 2001 From: "Li, Fei1" Date: Wed, 7 Aug 2019 23:29:18 +0800 Subject: [PATCH] hv: vpci: add each vdev_ops for each emulated PCI device Add a field (vdev_ops) in struct acrn_vm_pci_dev_config to configure a PCI CFG operation for an emulated PCI device. Use pci_pt_dev_ops for PCI_DEV_TYPE_PTDEV by default if there's no such configure. Tracked-On: #3475 Signed-off-by: Li, Fei1 Acked-by: Eddie Dong --- hypervisor/arch/x86/configs/pci_dev.c | 2 ++ hypervisor/dm/vpci/vhostbridge.c | 7 +------ hypervisor/dm/vpci/vpci.c | 12 ++++++------ hypervisor/include/arch/x86/vm_config.h | 1 + hypervisor/include/dm/vpci.h | 3 +-- hypervisor/scenarios/logical_partition/pci_dev.c | 3 +++ 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/hypervisor/arch/x86/configs/pci_dev.c b/hypervisor/arch/x86/configs/pci_dev.c index e97f91fac..f2e0be1a3 100644 --- a/hypervisor/arch/x86/configs/pci_dev.c +++ b/hypervisor/arch/x86/configs/pci_dev.c @@ -7,6 +7,7 @@ #include #include #include +#include /* * In theory, emulated PCI device doesn't need to bind to physical PCI device. @@ -19,6 +20,7 @@ struct acrn_vm_pci_dev_config sos_pci_devs[CONFIG_MAX_PCI_DEV_NUM] = { .emu_type = PCI_DEV_TYPE_HVEMUL, .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, .pbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, + .vdev_ops = &vhostbridge_ops, }, }; diff --git a/hypervisor/dm/vpci/vhostbridge.c b/hypervisor/dm/vpci/vhostbridge.c index bc48bf62f..a32cec805 100644 --- a/hypervisor/dm/vpci/vhostbridge.c +++ b/hypervisor/dm/vpci/vhostbridge.c @@ -122,14 +122,9 @@ static int32_t vhostbridge_write_cfg(struct pci_vdev *vdev, uint32_t offset, return 0; } -static const struct pci_vdev_ops vhostbridge_ops = { +const struct pci_vdev_ops vhostbridge_ops = { .init_vdev = init_vhostbridge, .deinit_vdev = deinit_vhostbridge, .write_vdev_cfg = vhostbridge_write_cfg, .read_vdev_cfg = vhostbridge_read_cfg, }; - -const struct pci_vdev_ops *get_vhostbridge_ops(void) -{ - return &vhostbridge_ops; -} diff --git a/hypervisor/dm/vpci/vpci.c b/hypervisor/dm/vpci/vpci.c index d77ab50aa..d1fa54b28 100644 --- a/hypervisor/dm/vpci/vpci.c +++ b/hypervisor/dm/vpci/vpci.c @@ -427,13 +427,13 @@ static void vpci_init_vdev(struct acrn_vpci *vpci, struct acrn_vm_pci_dev_config vdev->pdev = dev_config->pdev; vdev->pci_dev_config = dev_config; - if (dev_config->emu_type == PCI_DEV_TYPE_PTDEV) { - vdev->vdev_ops = &pci_pt_dev_ops; - ASSERT(dev_config->pdev != NULL, - "PCI PTDev %x:%x.%x is not present in the platform!", - dev_config->pbdf.b, dev_config->pbdf.d, dev_config->pbdf.f); + if (dev_config->vdev_ops != NULL) { + vdev->vdev_ops = dev_config->vdev_ops; } else { - vdev->vdev_ops = get_vhostbridge_ops(); + vdev->vdev_ops = &pci_pt_dev_ops; + ASSERT(dev_config->emu_type == PCI_DEV_TYPE_PTDEV, + "Only PCI_DEV_TYPE_PTDEV could not configure vdev_ops"); + ASSERT(dev_config->pdev != NULL, "PCI PTDev is not present on platform!"); } vdev->vdev_ops->init_vdev(vdev); diff --git a/hypervisor/include/arch/x86/vm_config.h b/hypervisor/include/arch/x86/vm_config.h index 62e41b18f..5ffa97bde 100644 --- a/hypervisor/include/arch/x86/vm_config.h +++ b/hypervisor/include/arch/x86/vm_config.h @@ -88,6 +88,7 @@ struct acrn_vm_pci_dev_config { union pci_bdf pbdf; /* physical BDF of PCI device */ uint64_t vbar_base[PCI_BAR_COUNT]; /* vbar base address of PCI device */ struct pci_pdev *pdev; /* the physical PCI device if it's a PT device */ + const struct pci_vdev_ops *vdev_ops; /* operations for PCI CFG read/write */ } __aligned(8); struct acrn_vm_config { diff --git a/hypervisor/include/dm/vpci.h b/hypervisor/include/dm/vpci.h index d3ef54cf5..8b3ba2b54 100644 --- a/hypervisor/include/dm/vpci.h +++ b/hypervisor/include/dm/vpci.h @@ -111,11 +111,10 @@ struct acrn_vpci { struct pci_vdev pci_vdevs[CONFIG_MAX_PCI_DEV_NUM]; }; +extern const struct pci_vdev_ops vhostbridge_ops; void vpci_init(struct acrn_vm *vm); void vpci_cleanup(const struct acrn_vm *vm); void vpci_set_ptdev_intr_info(const struct acrn_vm *target_vm, uint16_t vbdf, uint16_t pbdf); void vpci_reset_ptdev_intr_info(const struct acrn_vm *target_vm, uint16_t vbdf, uint16_t pbdf); -const struct pci_vdev_ops *get_vhostbridge_ops(void); - #endif /* VPCI_H_ */ diff --git a/hypervisor/scenarios/logical_partition/pci_dev.c b/hypervisor/scenarios/logical_partition/pci_dev.c index ac0aed08a..f71ce8f67 100644 --- a/hypervisor/scenarios/logical_partition/pci_dev.c +++ b/hypervisor/scenarios/logical_partition/pci_dev.c @@ -6,6 +6,7 @@ #include #include +#include /* The vbar_base info of pt devices is included in device MACROs which defined in * arch/x86/configs/$(CONFIG_BOARD)/pci_devices.h. @@ -16,6 +17,7 @@ struct acrn_vm_pci_dev_config vm0_pci_devs[VM0_CONFIG_PCI_DEV_NUM] = { { .emu_type = PCI_DEV_TYPE_HVEMUL, .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, + .vdev_ops = &vhostbridge_ops, }, { .emu_type = PCI_DEV_TYPE_PTDEV, @@ -33,6 +35,7 @@ struct acrn_vm_pci_dev_config vm1_pci_devs[VM1_CONFIG_PCI_DEV_NUM] = { { .emu_type = PCI_DEV_TYPE_HVEMUL, .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, + .vdev_ops = &vhostbridge_ops, }, { .emu_type = PCI_DEV_TYPE_PTDEV,