From be3fbaa461d3f540a3769f7555e8c2a0addd4aeb Mon Sep 17 00:00:00 2001 From: dongshen Date: Fri, 15 Feb 2019 12:47:24 -0800 Subject: [PATCH] HV: add generic vdev functions to vdev.c Add vdev functions so they can be reused by both partition mode and sharing mode code: pci_find_vdev_by_vbdf: search for vdev by virtual bdf pci_find_vdev_by_pbdf: search for vdev by physical bdf Tracked-On: #2534 Signed-off-by: dongshen Acked-by: Eddie Dong --- hypervisor/dm/vpci/pci_priv.h | 4 ++++ hypervisor/dm/vpci/vdev.c | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) 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; +}