HV: define function bdf_is_equal() to compare bdf

Use a function to compare bdf instead and some related code cleanup

Tracked-On: #2534
Signed-off-by: dongshen <dongsheng.x.zhang@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
dongshen 2019-02-22 15:25:04 -08:00 committed by Eddie Dong
parent 028663537a
commit 4d11985366
4 changed files with 20 additions and 8 deletions

View File

@ -34,17 +34,18 @@
static struct pci_vdev *partition_mode_find_vdev(struct acrn_vpci *vpci, union pci_bdf vbdf)
{
struct pci_vdev *vdev = NULL;
struct pci_vdev *vdev, *tmp;
struct acrn_vm_config *vm_config = get_vm_config(vpci->vm->vm_id);
int32_t i;
vdev = NULL;
for (i = 0; i < vm_config->pci_ptdev_num; i++) {
vdev = &vpci->vm->pci_vdevs[i];
tmp = &vpci->vm->pci_vdevs[i];
if (vdev->vbdf.value == vbdf.value) {
if (bdf_is_equal(&(tmp->vbdf), &vbdf)) {
vdev = tmp;
break;
}
vdev = NULL;
}
return vdev;

View File

@ -35,13 +35,16 @@ static struct pci_vdev sharing_mode_vdev_array[CONFIG_MAX_PCI_DEV_NUM];
struct pci_vdev *sharing_mode_find_vdev(union pci_bdf pbdf)
{
struct pci_vdev *vdev = NULL;
struct pci_vdev *vdev, *tmp;
uint32_t i;
vdev = NULL;
/* SOS_VM uses phys BDF */
for (i = 0U; i < num_pci_vdev; i++) {
if (sharing_mode_vdev_array[i].pdev->bdf.value == pbdf.value) {
vdev = &sharing_mode_vdev_array[i];
tmp = &sharing_mode_vdev_array[i];
if ((tmp->pdev != NULL) && bdf_is_equal((union pci_bdf*)&(tmp->pdev->bdf), &pbdf)) {
vdev = tmp;
break;
}
}

View File

@ -407,7 +407,7 @@ struct pci_pdev *find_pci_pdev(union pci_bdf pbdf)
uint32_t i;
for (i = 0U; i < num_pci_pdev; i++) {
if (pci_pdev_array[i].bdf.value == pbdf.value) {
if (bdf_is_equal(&pci_pdev_array[i].bdf, &pbdf)) {
pdev = &pci_pdev_array[i];
break;
}

View File

@ -220,6 +220,14 @@ static inline uint8_t pci_devfn(uint16_t bdf)
return (uint8_t)(bdf & 0xFFU);
}
/*
* @pre a != NULL && b != NULL
*/
static inline bool bdf_is_equal(const union pci_bdf *a, const union pci_bdf *b)
{
return (a->value == b->value);
}
uint32_t pci_pdev_read_cfg(union pci_bdf bdf, uint32_t offset, uint32_t bytes);
void pci_pdev_write_cfg(union pci_bdf bdf, uint32_t offset, uint32_t bytes, uint32_t val);
void enable_disable_pci_intx(union pci_bdf bdf, bool enable);