From 00f9b8507297909c35b28d9293460cc06d9b4412 Mon Sep 17 00:00:00 2001 From: dongshen Date: Mon, 25 Feb 2019 13:34:02 -0800 Subject: [PATCH] HV: move pci_vdevs[] array from vm.h to vpci.h pci_vdevs is vpci stuff so it would be better to make it managed by vpci rather than by vm.h, both sharing mode and partition mode can use pci_vdevs[] to maintain its own per vm vdev list. Tracked-On: #2534 Signed-off-by: dongshen Acked-by: Eddie Dong --- hypervisor/dm/vpci/partition_mode.c | 42 +++++++++++++++++--------- hypervisor/include/arch/x86/guest/vm.h | 3 +- hypervisor/include/dm/vpci.h | 3 +- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/hypervisor/dm/vpci/partition_mode.c b/hypervisor/dm/vpci/partition_mode.c index e238f88c2..372d2c6b0 100644 --- a/hypervisor/dm/vpci/partition_mode.c +++ b/hypervisor/dm/vpci/partition_mode.c @@ -33,15 +33,18 @@ #include #include "pci_priv.h" -static struct pci_vdev *partition_mode_find_vdev(struct acrn_vpci *vpci, union pci_bdf vbdf) + +/** + * @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; - struct acrn_vm_config *vm_config = get_vm_config(vpci->vm->vm_id); - int32_t i; + uint32_t i; vdev = NULL; - for (i = 0; i < vm_config->pci_ptdev_num; i++) { - tmp = &vpci->vm->pci_vdevs[i]; + 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; @@ -95,18 +98,27 @@ static void partition_mode_pdev_init(struct pci_vdev *vdev, union pci_bdf pbdf) } } +/** + * @pre vm != NULL + * @pre vm->vpci->pci_vdev_cnt <= CONFIG_MAX_PCI_DEV_NUM + * @pre vm_config != NULL + * @pre vdev != NULL + * @pre ptdev_config != NULL + */ static int32_t partition_mode_vpci_init(const struct acrn_vm *vm) { - const struct acrn_vpci *vpci = &vm->vpci; + struct acrn_vpci *vpci = (struct acrn_vpci *)&(vm->vpci); struct pci_vdev *vdev; struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id); struct acrn_vm_pci_ptdev_config *ptdev_config; - int32_t i; + uint32_t i; - for (i = 0; i < vm_config->pci_ptdev_num; i++) { - vdev = (struct pci_vdev *)&vm->pci_vdevs[i]; - ptdev_config = vm_config->pci_ptdevs + i; + vpci->pci_vdev_cnt = vm_config->pci_ptdev_num; + + for (i = 0U; i < vpci->pci_vdev_cnt; i++) { + vdev = &vpci->pci_vdevs[i]; vdev->vpci = vpci; + ptdev_config = &vm_config->pci_ptdevs[i]; vdev->vbdf.value = ptdev_config->vbdf.value; if (vdev->vbdf.value != 0U) { @@ -127,14 +139,16 @@ static int32_t partition_mode_vpci_init(const struct acrn_vm *vm) return 0; } +/** + * @pre vdev != NULL + */ static void partition_mode_vpci_deinit(const struct acrn_vm *vm) { struct pci_vdev *vdev; - struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id); - int32_t i; + uint32_t i; - for (i = 0; i < vm_config->pci_ptdev_num; i++) { - vdev = (struct pci_vdev *)&vm->pci_vdevs[i]; + for (i = 0U; i < vm->vpci.pci_vdev_cnt; i++) { + vdev = (struct pci_vdev *) &(vm->vpci.pci_vdevs[i]); if ((vdev->ops != NULL) && (vdev->ops->deinit != NULL)) { if (vdev->ops->deinit(vdev) != 0) { pr_err("vdev->ops->deinit failed!"); diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index 56e04f82f..334626869 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -146,10 +146,9 @@ struct acrn_vm { uint32_t vcpuid_entry_nr, vcpuid_level, vcpuid_xlevel; struct vcpuid_entry vcpuid_entries[MAX_VM_VCPUID_ENTRIES]; struct acrn_vpci vpci; + #ifdef CONFIG_PARTITION_MODE struct mptable_info mptable; - struct pci_vdev pci_vdevs[CONFIG_MAX_PCI_DEV_NUM]; - /* the valid number of pci_vdevs[] is vm_config->pci_ptdev_num */ uint8_t vrtc_offset; #endif diff --git a/hypervisor/include/dm/vpci.h b/hypervisor/include/dm/vpci.h index 2a7ebe61e..47a803d7e 100644 --- a/hypervisor/include/dm/vpci.h +++ b/hypervisor/include/dm/vpci.h @@ -119,11 +119,12 @@ struct vpci_ops { uint32_t bytes, uint32_t val); }; - struct acrn_vpci { struct acrn_vm *vm; struct pci_addr_info addr_info; const struct vpci_ops *ops; + uint32_t pci_vdev_cnt; + struct pci_vdev pci_vdevs[CONFIG_MAX_PCI_DEV_NUM]; }; #ifdef CONFIG_PARTITION_MODE