From 6794660e4f1c5c66d3f6c2c9cb75e22b9ef22278 Mon Sep 17 00:00:00 2001 From: dongshen Date: Fri, 15 Feb 2019 12:58:26 -0800 Subject: [PATCH] HV: use the common functions defined in vdev.c to reduce duplicate code Both sharing mode and parittioin mode code can use the pci_find_vdev_by_pbdf and pci_find_vdev_by_vbdf functions defined in vdev.c instead, and remove the corresponding functions in other files. Tracked-On: #2534 Signed-off-by: dongshen Acked-by: Eddie Dong --- hypervisor/dm/vpci/partition_mode.c | 25 ++----------------------- hypervisor/dm/vpci/sharing_mode.c | 22 +--------------------- 2 files changed, 3 insertions(+), 44 deletions(-) diff --git a/hypervisor/dm/vpci/partition_mode.c b/hypervisor/dm/vpci/partition_mode.c index 372d2c6b0..d234afe9f 100644 --- a/hypervisor/dm/vpci/partition_mode.c +++ b/hypervisor/dm/vpci/partition_mode.c @@ -34,27 +34,6 @@ #include "pci_priv.h" -/** - * @pre tmp != NULL - */ -static struct pci_vdev *partition_mode_find_vdev(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; -} - static inline bool is_valid_bar_type(const struct pci_bar *bar) { return (bar->type == PCIBAR_MEM32) || (bar->type == PCIBAR_MEM64); @@ -160,7 +139,7 @@ static void partition_mode_vpci_deinit(const struct acrn_vm *vm) static void partition_mode_cfgread(struct acrn_vpci *vpci, union pci_bdf vbdf, uint32_t offset, uint32_t bytes, uint32_t *val) { - struct pci_vdev *vdev = partition_mode_find_vdev(vpci, vbdf); + struct pci_vdev *vdev = pci_find_vdev_by_vbdf(vpci, vbdf); if ((vdev != NULL) && (vdev->ops != NULL) && (vdev->ops->cfgread != NULL)) { @@ -171,7 +150,7 @@ static void partition_mode_cfgread(struct acrn_vpci *vpci, union pci_bdf vbdf, static void partition_mode_cfgwrite(struct acrn_vpci *vpci, union pci_bdf vbdf, uint32_t offset, uint32_t bytes, uint32_t val) { - struct pci_vdev *vdev = partition_mode_find_vdev(vpci, vbdf); + struct pci_vdev *vdev = pci_find_vdev_by_vbdf(vpci, vbdf); if ((vdev != NULL) && (vdev->ops != NULL) && (vdev->ops->cfgwrite != NULL)) { diff --git a/hypervisor/dm/vpci/sharing_mode.c b/hypervisor/dm/vpci/sharing_mode.c index 87af9816f..7f4d4c875 100644 --- a/hypervisor/dm/vpci/sharing_mode.c +++ b/hypervisor/dm/vpci/sharing_mode.c @@ -33,26 +33,6 @@ #include "pci_priv.h" -/** - * @pre tmp != NULL - */ -static struct pci_vdev *sharing_mode_find_vdev(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; -} - /** * @pre vpci != NULL */ @@ -65,7 +45,7 @@ static struct pci_vdev *sharing_mode_find_vdev_sos(union pci_bdf pbdf) vm = get_sos_vm(); if (vm != NULL) { vpci = &vm->vpci; - vdev = sharing_mode_find_vdev(vpci, pbdf); + vdev = pci_find_vdev_by_pbdf(vpci, pbdf); } return vdev;