diff --git a/hypervisor/dm/vpci/pci_priv.h b/hypervisor/dm/vpci/pci_priv.h index 3320b38c0..d5a0a8382 100644 --- a/hypervisor/dm/vpci/pci_priv.h +++ b/hypervisor/dm/vpci/pci_priv.h @@ -81,4 +81,8 @@ void populate_msi_struct(struct pci_vdev *vdev); void add_vdev_handler(struct pci_vdev *vdev, const struct pci_vdev_ops *ops); +struct pci_vdev *pci_find_vdev_by_vbdf(const struct acrn_vpci *vpci, union pci_bdf vbdf); + +struct pci_vdev *pci_find_vdev_by_pbdf(const struct acrn_vpci *vpci, union pci_bdf pbdf); + #endif /* PCI_PRIV_H_ */ diff --git a/hypervisor/dm/vpci/vdev.c b/hypervisor/dm/vpci/vdev.c index b714056b7..2f361953f 100644 --- a/hypervisor/dm/vpci/vdev.c +++ b/hypervisor/dm/vpci/vdev.c @@ -63,3 +63,45 @@ void pci_vdev_write_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, break; } } + +/** + * @pre tmp != NULL + */ +struct pci_vdev *pci_find_vdev_by_vbdf(const struct acrn_vpci *vpci, union pci_bdf vbdf) +{ + struct pci_vdev *vdev, *tmp; + uint32_t i; + + vdev = NULL; + for (i = 0U; i < vpci->pci_vdev_cnt; i++) { + tmp = (struct pci_vdev *)&(vpci->pci_vdevs[i]); + + if (bdf_is_equal(&(tmp->vbdf), &vbdf)) { + vdev = tmp; + break; + } + } + + return vdev; +} + +/** + * @pre tmp != NULL + */ +struct pci_vdev *pci_find_vdev_by_pbdf(const struct acrn_vpci *vpci, union pci_bdf pbdf) +{ + struct pci_vdev *vdev, *tmp; + uint32_t i; + + vdev = NULL; + for (i = 0U; i < vpci->pci_vdev_cnt; i++) { + tmp = (struct pci_vdev *)&(vpci->pci_vdevs[i]); + + if ((tmp->pdev != NULL) && bdf_is_equal((union pci_bdf *)&(tmp->pdev->bdf), &pbdf)) { + vdev = tmp; + break; + } + } + + return vdev; +}