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 <dongsheng.x.zhang@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
dongshen 2019-02-15 12:58:26 -08:00 committed by Eddie Dong
parent be3fbaa461
commit 6794660e4f
2 changed files with 3 additions and 44 deletions

View File

@ -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)) {

View File

@ -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;