diff --git a/hypervisor/arch/x86/configs/apl-mrb/partition_config.h b/hypervisor/arch/x86/configs/apl-mrb/partition_config.h index f79a2a66c..04af8a3cb 100644 --- a/hypervisor/arch/x86/configs/apl-mrb/partition_config.h +++ b/hypervisor/arch/x86/configs/apl-mrb/partition_config.h @@ -37,6 +37,10 @@ console=ttyS2 no_timer_check ignore_loglevel log_buf_len=16M \ consoleblank=0 tsc=reliable xapic_phys" -extern struct vpci_vdev_array vpci_vdev_array0, vpci_vdev_array1; +#define VM0_CONFIG_PCI_PTDEV_NUM 2U +#define VM1_CONFIG_PCI_PTDEV_NUM 3U + +extern struct acrn_vm_pci_ptdev_config vm0_pci_ptdevs[VM0_CONFIG_PCI_PTDEV_NUM]; +extern struct acrn_vm_pci_ptdev_config vm1_pci_ptdevs[VM1_CONFIG_PCI_PTDEV_NUM]; #endif /* PARTITION_CONFIG_H */ diff --git a/hypervisor/arch/x86/configs/apl-mrb/pt_dev.c b/hypervisor/arch/x86/configs/apl-mrb/pt_dev.c index c72503fed..956fd7753 100644 --- a/hypervisor/arch/x86/configs/apl-mrb/pt_dev.c +++ b/hypervisor/arch/x86/configs/apl-mrb/pt_dev.c @@ -6,39 +6,28 @@ #include -struct vpci_vdev_array vpci_vdev_array0 = { - .num_pci_vdev = 2, - - .vpci_vdev_list = { - {/*vdev 0: hostbridge */ - .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x0U}, - .pbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x0U}, - }, - - {/*vdev 1: SATA controller*/ - .vbdf.bits = {.b = 0x00U, .d = 0x01U, .f = 0x0U}, - .pbdf.bits = {.b = 0x00U, .d = 0x12U, .f = 0x0U}, - }, - } +struct acrn_vm_pci_ptdev_config vm0_pci_ptdevs[2] = { + { + .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, + .pbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, + }, + { + .vbdf.bits = {.b = 0x00U, .d = 0x01U, .f = 0x00U}, + .pbdf.bits = {.b = 0x00U, .d = 0x12U, .f = 0x00U}, + }, }; -struct vpci_vdev_array vpci_vdev_array1 = { - .num_pci_vdev = 3, - - .vpci_vdev_list = { - {/*vdev 0: hostbridge*/ - .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x0U}, - .pbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x0U}, - }, - - {/*vdev 1: USB controller*/ - .vbdf.bits = {.b = 0x00U, .d = 0x01U, .f = 0x0U}, - .pbdf.bits = {.b = 0x00U, .d = 0x15U, .f = 0x0U}, - }, - - {/*vdev 2: Ethernet*/ - .vbdf.bits = {.b = 0x00U, .d = 0x02U, .f = 0x0U}, - .pbdf.bits = {.b = 0x02U, .d = 0x00U, .f = 0x0U}, - }, - } +struct acrn_vm_pci_ptdev_config vm1_pci_ptdevs[3] = { + { + .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, + .pbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, + }, + { + .vbdf.bits = {.b = 0x00U, .d = 0x01U, .f = 0x00U}, + .pbdf.bits = {.b = 0x00U, .d = 0x15U, .f = 0x00U}, + }, + { + .vbdf.bits = {.b = 0x00U, .d = 0x02U, .f = 0x00U}, + .pbdf.bits = {.b = 0x02U, .d = 0x00U, .f = 0x00U}, + }, }; diff --git a/hypervisor/arch/x86/configs/dnv-cb2/partition_config.h b/hypervisor/arch/x86/configs/dnv-cb2/partition_config.h index 9390922e4..739e56c63 100644 --- a/hypervisor/arch/x86/configs/dnv-cb2/partition_config.h +++ b/hypervisor/arch/x86/configs/dnv-cb2/partition_config.h @@ -37,6 +37,10 @@ "console=ttyS0 no_timer_check ignore_loglevel log_buf_len=16M "\ "consoleblank=0 tsc=reliable xapic_phys apic_debug" -extern struct vpci_vdev_array vpci_vdev_array0, vpci_vdev_array1; +#define VM0_CONFIG_PCI_PTDEV_NUM 3U +#define VM1_CONFIG_PCI_PTDEV_NUM 3U + +extern struct acrn_vm_pci_ptdev_config vm0_pci_ptdevs[VM0_CONFIG_PCI_PTDEV_NUM]; +extern struct acrn_vm_pci_ptdev_config vm1_pci_ptdevs[VM1_CONFIG_PCI_PTDEV_NUM]; #endif /* PARTITION_CONFIG_H */ diff --git a/hypervisor/arch/x86/configs/dnv-cb2/pt_dev.c b/hypervisor/arch/x86/configs/dnv-cb2/pt_dev.c index a4dfbdfd5..cb0a414b2 100644 --- a/hypervisor/arch/x86/configs/dnv-cb2/pt_dev.c +++ b/hypervisor/arch/x86/configs/dnv-cb2/pt_dev.c @@ -6,44 +6,32 @@ #include -struct vpci_vdev_array vpci_vdev_array0 = { - .num_pci_vdev = 3, - - .vpci_vdev_list = { - {/*vdev 0: hostbridge */ - .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x0U}, - .pbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x0U}, - }, - - {/*vdev 1: Ethernet*/ - .vbdf.bits = {.b = 0x00U, .d = 0x01U, .f = 0x0U}, - .pbdf.bits = {.b = 0x03U, .d = 0x00U, .f = 0x1U}, - }, - - {/*vdev 2: USB*/ - .vbdf.bits = {.b = 0x00U, .d = 0x02U, .f = 0x0U}, - .pbdf.bits = {.b = 0x00U, .d = 0x15U, .f = 0x0U}, - }, - } +struct acrn_vm_pci_ptdev_config vm0_pci_ptdevs[3] = { + { + .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, + .pbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, + }, + { + .vbdf.bits = {.b = 0x00U, .d = 0x01U, .f = 0x00U}, + .pbdf.bits = {.b = 0x03U, .d = 0x00U, .f = 0x01U}, + }, + { + .vbdf.bits = {.b = 0x00U, .d = 0x02U, .f = 0x00U}, + .pbdf.bits = {.b = 0x00U, .d = 0x15U, .f = 0x00U}, + }, }; -struct vpci_vdev_array vpci_vdev_array1 = { - .num_pci_vdev = 3, - - .vpci_vdev_list = { - {/*vdev 0: hostbridge*/ - .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x0U}, - .pbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x0U}, - }, - - {/*vdev 1: SATA controller*/ - .vbdf.bits = {.b = 0x00U, .d = 0x05U, .f = 0x0U}, - .pbdf.bits = {.b = 0x00U, .d = 0x14U, .f = 0x0U}, - }, - - {/*vdev 2: Ethernet*/ - .vbdf.bits = {.b = 0x00U, .d = 0x06U, .f = 0x0U}, - .pbdf.bits = {.b = 0x03U, .d = 0x00U, .f = 0x0U}, - }, - } +struct acrn_vm_pci_ptdev_config vm1_pci_ptdevs[3] = { + { + .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, + .pbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, + }, + { + .vbdf.bits = {.b = 0x00U, .d = 0x01U, .f = 0x00U}, + .pbdf.bits = {.b = 0x00U, .d = 0x14U, .f = 0x00U}, + }, + { + .vbdf.bits = {.b = 0x00U, .d = 0x02U, .f = 0x00U}, + .pbdf.bits = {.b = 0x03U, .d = 0x00U, .f = 0x00U}, + }, }; diff --git a/hypervisor/arch/x86/configs/partition_config.c b/hypervisor/arch/x86/configs/partition_config.c index 78b0ea7cb..f0e743ecf 100644 --- a/hypervisor/arch/x86/configs/partition_config.c +++ b/hypervisor/arch/x86/configs/partition_config.c @@ -22,7 +22,8 @@ .bootargs = VM##idx##_CONFIG_OS_BOOTARGS, \ }, \ .vm_vuart = true, \ - .vpci_vdev_array = &vpci_vdev_array##idx, \ + .pci_ptdev_num = VM##idx##_CONFIG_PCI_PTDEV_NUM, \ + .pci_ptdevs = vm##idx##_pci_ptdevs, \ }, struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] __aligned(PAGE_SIZE) = { diff --git a/hypervisor/dm/vpci/partition_mode.c b/hypervisor/dm/vpci/partition_mode.c index 2e5e1bd1e..52a710974 100644 --- a/hypervisor/dm/vpci/partition_mode.c +++ b/hypervisor/dm/vpci/partition_mode.c @@ -34,20 +34,20 @@ static struct pci_vdev *partition_mode_find_vdev(struct acrn_vpci *vpci, union pci_bdf vbdf) { - struct vpci_vdev_array *vdev_array; - struct pci_vdev *vdev; + struct pci_vdev *vdev = NULL; struct acrn_vm_config *vm_config = get_vm_config(vpci->vm->vm_id); int32_t i; - vdev_array = vm_config->vpci_vdev_array; - for (i = 0; i < vdev_array->num_pci_vdev; i++) { - vdev = &vdev_array->vpci_vdev_list[i]; + for (i = 0; i < vm_config->pci_ptdev_num; i++) { + vdev = &vpci->vm->pci_vdevs[i]; + if (vdev->vbdf.value == vbdf.value) { - return vdev; + break; } + vdev = NULL; } - return NULL; + return vdev; } static inline bool is_valid_bar_type(const struct pci_bar *bar) @@ -95,17 +95,18 @@ static void partition_mode_pdev_init(struct pci_vdev *vdev) static int32_t partition_mode_vpci_init(const struct acrn_vm *vm) { - struct vpci_vdev_array *vdev_array; const struct acrn_vpci *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; - vdev_array = vm_config->vpci_vdev_array; - - for (i = 0; i < vdev_array->num_pci_vdev; i++) { - vdev = &vdev_array->vpci_vdev_list[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; vdev->vpci = vpci; + vdev->vbdf.value = ptdev_config->vbdf.value; + vdev->pbdf.value = ptdev_config->pbdf.value; if (vdev->vbdf.value != 0U) { partition_mode_pdev_init(vdev); @@ -127,15 +128,12 @@ static int32_t partition_mode_vpci_init(const struct acrn_vm *vm) static void partition_mode_vpci_deinit(const struct acrn_vm *vm) { - struct vpci_vdev_array *vdev_array; struct pci_vdev *vdev; struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id); int32_t i; - vdev_array = vm_config->vpci_vdev_array; - - for (i = 0; i < vdev_array->num_pci_vdev; i++) { - vdev = &vdev_array->vpci_vdev_list[i]; + for (i = 0; i < vm_config->pci_ptdev_num; i++) { + vdev = (struct pci_vdev *)&vm->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 1a58eac98..38a84832d 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -154,6 +154,8 @@ struct acrn_vm { 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 @@ -163,13 +165,6 @@ struct acrn_vm { bool snoopy_mem; } __aligned(PAGE_SIZE); -#ifdef CONFIG_PARTITION_MODE -struct vpci_vdev_array { - int32_t num_pci_vdev; - struct pci_vdev vpci_vdev_list[]; -}; -#endif - #define MAX_BOOTARGS_SIZE 1024U #define MAX_CONFIG_NAME_SIZE 32U