From a6503c6af31189521fc30e30c3f012e643f3a5ff Mon Sep 17 00:00:00 2001 From: dongshen Date: Tue, 21 May 2019 14:40:49 -0700 Subject: [PATCH] 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 Reviewed-by: Eddie Dong --- hypervisor/arch/x86/configs/vm_config.c | 2 +- hypervisor/dm/vpci/vpci.c | 23 ++++++++++++++++++----- hypervisor/hw/pci.c | 15 ++------------- hypervisor/include/hw/pci.h | 5 +++-- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/hypervisor/arch/x86/configs/vm_config.c b/hypervisor/arch/x86/configs/vm_config.c index 1a0c95593..17eb754a6 100644 --- a/hypervisor/arch/x86/configs/vm_config.c +++ b/hypervisor/arch/x86/configs/vm_config.c @@ -10,7 +10,7 @@ /* * @pre vm_id < CONFIG_MAX_VM_NUM - * @post return != NULL + * @post return != NULL */ struct acrn_vm_config *get_vm_config(uint16_t vm_id) { diff --git a/hypervisor/dm/vpci/vpci.c b/hypervisor/dm/vpci/vpci.c index 2c3174bce..ca20da30d 100644 --- a/hypervisor/dm/vpci/vpci.c +++ b/hypervisor/dm/vpci/vpci.c @@ -34,7 +34,7 @@ #include #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_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); @@ -208,8 +208,8 @@ void vpci_init(struct acrn_vm *vm) case PRE_LAUNCHED_VM: case SOS_VM: vm->iommu = create_iommu_domain(vm->vm_id, hva2hpa(vm->arch_vm.nworld_eptp), 48U); - /* Build up vdev array for vm */ - pci_pdev_foreach(init_vdev_for_pdev, vm); + /* Build up vdev list for vm */ + init_vdevs(vm); ret = 0; 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->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_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->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(); vdev->vpci = &vm->vpci; + /* vbdf equals to pbdf in sos */ vdev->vbdf.value = vdev->pdev->bdf.value; } diff --git a/hypervisor/hw/pci.c b/hypervisor/hw/pci.c index c48676baa..843b601b8 100644 --- a/hypervisor/hw/pci.c +++ b/hypervisor/hw/pci.c @@ -36,8 +36,8 @@ #include static spinlock_t pci_device_lock; -static uint32_t num_pci_pdev; -static struct pci_pdev pci_pdev_array[CONFIG_MAX_PCI_DEV_NUM]; +uint32_t num_pci_pdev; +struct pci_pdev pci_pdev_array[CONFIG_MAX_PCI_DEV_NUM]; 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 *pdev = NULL; diff --git a/hypervisor/include/hw/pci.h b/hypervisor/include/hw/pci.h index 4468293ea..d4eb6e47e 100644 --- a/hypervisor/include/hw/pci.h +++ b/hypervisor/include/hw/pci.h @@ -179,7 +179,9 @@ struct pci_pdev { 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) { @@ -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 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); void init_pci_pdev_list(void);