Skip to content

Commit 176cb31

Browse files
yliu80wenlingz
authored andcommitted
hv: refine vpci_init_vdev function
Add a new parameter pf_vdev for function vpci_init_vdev to support SRIOV VF vdev initializaiton. Tracked-On: #4433 Signed-off-by: Yuan Liu <yuan1.liu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 320ed6c commit 176cb31

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

hypervisor/dm/vpci/vpci.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,24 @@ static int32_t write_cfg(struct acrn_vpci *vpci, union pci_bdf bdf,
483483
}
484484

485485
/**
486+
* @brief Initialize a vdev structure.
487+
*
488+
* The function vpci_init_vdev is used to initialize a vdev structure with a PCI device configuration(dev_config)
489+
* on a specified vPCI bus(vpci). If the function vpci_init_vdev initializes a SRIOV Virtual Function(VF) vdev structure,
490+
* the parameter parent_pf_vdev is the VF associated Physical Function(PF) vdev structure, otherwise the parameter parent_pf_vdev is NULL.
491+
* The caller of the function vpci_init_vdev should guarantee execution atomically.
492+
*
493+
* @param vpci Pointer to a vpci structure
494+
* @param dev_config Pointer to a dev_config structure of the vdev
495+
* @param parent_pf_vdev If the parameter def_config points to a SRIOV VF vdev, this parameter parent_pf_vdev indicates the parent PF vdev.
496+
* Otherwise, it is NULL.
497+
*
486498
* @pre vpci != NULL
487499
* @pre vpci.pci_vdev_cnt <= CONFIG_MAX_PCI_DEV_NUM
500+
*
501+
* @return If there's a successfully initialized vdev structure return it, otherwise return NULL;
488502
*/
489-
static struct pci_vdev *vpci_init_vdev(struct acrn_vpci *vpci, struct acrn_vm_pci_dev_config *dev_config)
503+
struct pci_vdev *vpci_init_vdev(struct acrn_vpci *vpci, struct acrn_vm_pci_dev_config *dev_config, struct pci_vdev *parent_pf_vdev)
490504
{
491505
struct pci_vdev *vdev = &vpci->pci_vdevs[vpci->pci_vdev_cnt];
492506

@@ -495,6 +509,7 @@ static struct pci_vdev *vpci_init_vdev(struct acrn_vpci *vpci, struct acrn_vm_pc
495509
vdev->bdf.value = dev_config->vbdf.value;
496510
vdev->pdev = dev_config->pdev;
497511
vdev->pci_dev_config = dev_config;
512+
vdev->phyfun = parent_pf_vdev;
498513

499514
if (dev_config->vdev_ops != NULL) {
500515
vdev->vdev_ops = dev_config->vdev_ops;
@@ -525,7 +540,7 @@ static void vpci_init_vdevs(struct acrn_vm *vm)
525540
const struct acrn_vm_config *vm_config = get_vm_config(vpci->vm->vm_id);
526541

527542
for (idx = 0U; idx < vm_config->pci_dev_num; idx++) {
528-
(void)vpci_init_vdev(vpci, &vm_config->pci_devs[idx]);
543+
(void)vpci_init_vdev(vpci, &vm_config->pci_devs[idx], NULL);
529544
}
530545
}
531546

@@ -632,7 +647,7 @@ int32_t vpci_assign_pcidev(struct acrn_vm *tgt_vm, struct acrn_assign_pcidev *pc
632647
vdev_in_sos->vpci = vpci;
633648

634649
spinlock_obtain(&tgt_vm->vpci.lock);
635-
vdev = vpci_init_vdev(vpci, vdev_in_sos->pci_dev_config);
650+
vdev = vpci_init_vdev(vpci, vdev_in_sos->pci_dev_config, NULL);
636651
pci_vdev_write_cfg_u8(vdev, PCIR_INTERRUPT_LINE, pcidev->intr_line);
637652
pci_vdev_write_cfg_u8(vdev, PCIR_INTERRUPT_PIN, pcidev->intr_pin);
638653
for (idx = 0U; idx < vdev->nr_bars; idx++) {

hypervisor/include/dm/vpci.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ struct pci_vdev {
112112
struct pci_msix msix;
113113
struct pci_cap_sriov sriov;
114114

115+
/* Pointer to the SRIOV VF associated PF's vdev */
116+
struct pci_vdev *phyfun;
117+
115118
/* Pointer to corresponding PCI device's vm_config */
116119
struct acrn_vm_pci_dev_config *pci_dev_config;
117120

@@ -149,5 +152,6 @@ struct pci_vdev *pci_find_vdev(struct acrn_vpci *vpci, union pci_bdf vbdf);
149152
struct acrn_assign_pcidev;
150153
int32_t vpci_assign_pcidev(struct acrn_vm *tgt_vm, struct acrn_assign_pcidev *pcidev);
151154
int32_t vpci_deassign_pcidev(struct acrn_vm *tgt_vm, struct acrn_assign_pcidev *pcidev);
155+
struct pci_vdev *vpci_init_vdev(struct acrn_vpci *vpci, struct acrn_vm_pci_dev_config *dev_config, struct pci_vdev *parent_pf_vdev);
152156

153157
#endif /* VPCI_H_ */

0 commit comments

Comments
 (0)