HV: remove function pci_pdev_foreach()

And make other related changes accordingly:
 Remove pci_pdev_enumeration_cb define
 Create init_vdevs() to iterate through the pdev list and create vdev for each pdev
 Export num_pci_pdev and pci_pdev_array as globals in header file

Minor cosmetic fix:
 Remove trailing whitespace

Tracked-On: #3022
Signed-off-by: dongshen <dongsheng.x.zhang@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
dongshen 2019-05-21 14:40:49 -07:00 committed by ACRN System Integration
parent 536c69b9ff
commit a6503c6af3
4 changed files with 24 additions and 21 deletions

View File

@ -10,7 +10,7 @@
/* /*
* @pre vm_id < CONFIG_MAX_VM_NUM * @pre vm_id < CONFIG_MAX_VM_NUM
* @post return != NULL * @post return != NULL
*/ */
struct acrn_vm_config *get_vm_config(uint16_t vm_id) struct acrn_vm_config *get_vm_config(uint16_t vm_id)
{ {

View File

@ -34,7 +34,7 @@
#include <logmsg.h> #include <logmsg.h>
#include "vpci_priv.h" #include "vpci_priv.h"
static void init_vdev_for_pdev(struct pci_pdev *pdev, const void *vm); static void init_vdevs(const struct acrn_vm *vm);
static void deinit_prelaunched_vm_vpci(const struct acrn_vm *vm); static void deinit_prelaunched_vm_vpci(const struct acrn_vm *vm);
static void deinit_postlaunched_vm_vpci(const struct acrn_vm *vm); static void deinit_postlaunched_vm_vpci(const struct acrn_vm *vm);
static void read_cfg(const struct acrn_vpci *vpci, union pci_bdf bdf, uint32_t offset, uint32_t bytes, uint32_t *val); static void read_cfg(const struct acrn_vpci *vpci, union pci_bdf bdf, uint32_t offset, uint32_t bytes, uint32_t *val);
@ -208,8 +208,8 @@ void vpci_init(struct acrn_vm *vm)
case PRE_LAUNCHED_VM: case PRE_LAUNCHED_VM:
case SOS_VM: case SOS_VM:
vm->iommu = create_iommu_domain(vm->vm_id, hva2hpa(vm->arch_vm.nworld_eptp), 48U); vm->iommu = create_iommu_domain(vm->vm_id, hva2hpa(vm->arch_vm.nworld_eptp), 48U);
/* Build up vdev array for vm */ /* Build up vdev list for vm */
pci_pdev_foreach(init_vdev_for_pdev, vm); init_vdevs(vm);
ret = 0; ret = 0;
break; break;
@ -398,9 +398,9 @@ static struct acrn_vm_pci_ptdev_config *find_ptdev_config_by_pbdf(const struct a
* @pre vm != NULL * @pre vm != NULL
* @pre vm->vpci.pci_vdev_cnt <= CONFIG_MAX_PCI_DEV_NUM * @pre vm->vpci.pci_vdev_cnt <= CONFIG_MAX_PCI_DEV_NUM
*/ */
static void init_vdev_for_pdev(struct pci_pdev *pdev, const void *vm) static void init_vdev_for_pdev(struct pci_pdev *pdev, const struct acrn_vm *vm)
{ {
const struct acrn_vm_config *vm_config = get_vm_config(((struct acrn_vm *)vm)->vm_id); const struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
struct acrn_vpci *vpci = &(((struct acrn_vm *)vm)->vpci); struct acrn_vpci *vpci = &(((struct acrn_vm *)vm)->vpci);
struct acrn_vm_pci_ptdev_config *ptdev_config; struct acrn_vm_pci_ptdev_config *ptdev_config;
@ -450,6 +450,18 @@ static void init_vdev_for_pdev(struct pci_pdev *pdev, const void *vm)
} }
} }
/**
* @pre vm != NULL
*/
static void init_vdevs(const struct acrn_vm *vm)
{
uint32_t idx;
for (idx = 0U; idx < num_pci_pdev; idx++) {
init_vdev_for_pdev(&pci_pdev_array[idx], vm);
}
}
/** /**
* @pre vm != NULL * @pre vm != NULL
* @pre vm->vpci.pci_vdev_cnt <= CONFIG_MAX_PCI_DEV_NUM * @pre vm->vpci.pci_vdev_cnt <= CONFIG_MAX_PCI_DEV_NUM
@ -561,6 +573,7 @@ void vpci_reset_ptdev_intr_info(const struct acrn_vm *target_vm, uint16_t vbdf,
vm = get_sos_vm(); vm = get_sos_vm();
vdev->vpci = &vm->vpci; vdev->vpci = &vm->vpci;
/* vbdf equals to pbdf in sos */ /* vbdf equals to pbdf in sos */
vdev->vbdf.value = vdev->pdev->bdf.value; vdev->vbdf.value = vdev->pdev->bdf.value;
} }

View File

@ -36,8 +36,8 @@
#include <logmsg.h> #include <logmsg.h>
static spinlock_t pci_device_lock; static spinlock_t pci_device_lock;
static uint32_t num_pci_pdev; uint32_t num_pci_pdev;
static struct pci_pdev pci_pdev_array[CONFIG_MAX_PCI_DEV_NUM]; struct pci_pdev pci_pdev_array[CONFIG_MAX_PCI_DEV_NUM];
static void init_pdev(uint16_t pbdf); static void init_pdev(uint16_t pbdf);
@ -395,17 +395,6 @@ static void init_pdev(uint16_t pbdf)
} }
} }
void pci_pdev_foreach(pci_pdev_enumeration_cb cb_func, const void *ctx)
{
uint32_t idx;
for (idx = 0U; idx < num_pci_pdev; idx++) {
if (cb_func != NULL) {
cb_func(&pci_pdev_array[idx], ctx);
}
}
}
struct pci_pdev *find_pci_pdev(union pci_bdf pbdf) struct pci_pdev *find_pci_pdev(union pci_bdf pbdf)
{ {
struct pci_pdev *pdev = NULL; struct pci_pdev *pdev = NULL;

View File

@ -179,7 +179,9 @@ struct pci_pdev {
struct pci_msix_cap msix; struct pci_msix_cap msix;
}; };
typedef void (*pci_pdev_enumeration_cb)(struct pci_pdev *pdev, const void *data); extern uint32_t num_pci_pdev;
extern struct pci_pdev pci_pdev_array[CONFIG_MAX_PCI_DEV_NUM];
static inline uint32_t pci_bar_offset(uint32_t idx) static inline uint32_t pci_bar_offset(uint32_t idx)
{ {
@ -249,7 +251,6 @@ 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 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); void enable_disable_pci_intx(union pci_bdf bdf, bool enable);
void pci_pdev_foreach(pci_pdev_enumeration_cb cb, const void *ctx);
struct pci_pdev *find_pci_pdev(union pci_bdf pbdf); struct pci_pdev *find_pci_pdev(union pci_bdf pbdf);
void init_pci_pdev_list(void); void init_pci_pdev_list(void);