@@ -483,10 +483,24 @@ static int32_t write_cfg(struct acrn_vpci *vpci, union pci_bdf bdf,
483
483
}
484
484
485
485
/**
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
+ *
486
498
* @pre vpci != NULL
487
499
* @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;
488
502
*/
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 )
490
504
{
491
505
struct pci_vdev * vdev = & vpci -> pci_vdevs [vpci -> pci_vdev_cnt ];
492
506
@@ -495,6 +509,7 @@ static struct pci_vdev *vpci_init_vdev(struct acrn_vpci *vpci, struct acrn_vm_pc
495
509
vdev -> bdf .value = dev_config -> vbdf .value ;
496
510
vdev -> pdev = dev_config -> pdev ;
497
511
vdev -> pci_dev_config = dev_config ;
512
+ vdev -> phyfun = parent_pf_vdev ;
498
513
499
514
if (dev_config -> vdev_ops != NULL ) {
500
515
vdev -> vdev_ops = dev_config -> vdev_ops ;
@@ -525,7 +540,7 @@ static void vpci_init_vdevs(struct acrn_vm *vm)
525
540
const struct acrn_vm_config * vm_config = get_vm_config (vpci -> vm -> vm_id );
526
541
527
542
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 );
529
544
}
530
545
}
531
546
@@ -632,7 +647,7 @@ int32_t vpci_assign_pcidev(struct acrn_vm *tgt_vm, struct acrn_assign_pcidev *pc
632
647
vdev_in_sos -> vpci = vpci ;
633
648
634
649
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 );
636
651
pci_vdev_write_cfg_u8 (vdev , PCIR_INTERRUPT_LINE , pcidev -> intr_line );
637
652
pci_vdev_write_cfg_u8 (vdev , PCIR_INTERRUPT_PIN , pcidev -> intr_pin );
638
653
for (idx = 0U ; idx < vdev -> nr_bars ; idx ++ ) {
0 commit comments