From ff54fa2325b74a5d30ae9a239eb48a44f3bf5d01 Mon Sep 17 00:00:00 2001 From: "Li, Fei1" Date: Wed, 7 Aug 2019 22:06:11 +0800 Subject: [PATCH] hv: vpci: add emulated PCI device configure for SOS Add emulated PCI device configure for SOS to prepare for add support for customizing special pci operations for each emulated PCI device. Tracked-On: #3475 Signed-off-by: Li, Fei1 --- hypervisor/Makefile | 4 +- hypervisor/arch/x86/configs/pci_dev.c | 59 +++++++++++++------ hypervisor/arch/x86/guest/vm.c | 2 - hypervisor/include/arch/x86/pci_dev.h | 8 ++- .../scenarios/hybrid/vm_configurations.c | 3 + .../scenarios/industry/vm_configurations.c | 5 +- .../logical_partition/{pt_dev.c => pci_dev.c} | 4 +- .../logical_partition/vm_configurations.c | 8 +-- .../logical_partition/vm_configurations.h | 6 +- hypervisor/scenarios/sdc/vm_configurations.c | 5 +- hypervisor/scenarios/sdc2/vm_configurations.c | 5 +- 11 files changed, 73 insertions(+), 36 deletions(-) rename hypervisor/scenarios/logical_partition/{pt_dev.c => pci_dev.c} (88%) diff --git a/hypervisor/Makefile b/hypervisor/Makefile index 1af40663d..660818a42 100644 --- a/hypervisor/Makefile +++ b/hypervisor/Makefile @@ -213,8 +213,8 @@ HW_C_SRCS += hw/pci.c HW_C_SRCS += arch/x86/configs/vm_config.c HW_C_SRCS += arch/x86/configs/$(CONFIG_BOARD)/board.c HW_C_SRCS += scenarios/$(SCENARIO_NAME)/vm_configurations.c -ifneq (,$(wildcard scenarios/$(SCENARIO_NAME)/pt_dev.c)) -HW_C_SRCS += scenarios/$(SCENARIO_NAME)/pt_dev.c +ifneq (,$(wildcard scenarios/$(SCENARIO_NAME)/pci_dev.c)) +HW_C_SRCS += scenarios/$(SCENARIO_NAME)/pci_dev.c endif HW_C_SRCS += boot/acpi_base.c HW_C_SRCS += boot/dmar_info.c diff --git a/hypervisor/arch/x86/configs/pci_dev.c b/hypervisor/arch/x86/configs/pci_dev.c index 1db2e390c..e97f91fac 100644 --- a/hypervisor/arch/x86/configs/pci_dev.c +++ b/hypervisor/arch/x86/configs/pci_dev.c @@ -6,9 +6,21 @@ #include #include +#include -static uint16_t pcidev_config_num = 0U; -static struct acrn_vm_pci_dev_config pcidev_config[CONFIG_MAX_PCI_DEV_NUM] = {}; +/* + * In theory, emulated PCI device doesn't need to bind to physical PCI device. + * However, now we need to search virtual PCI device by pBDF because we bind + * post-launched VM PTDev with SOS's. + * Remove the pBDF for emulated PCI device once we don't have this limit. + */ +struct acrn_vm_pci_dev_config sos_pci_devs[CONFIG_MAX_PCI_DEV_NUM] = { + { + .emu_type = PCI_DEV_TYPE_HVEMUL, + .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, + .pbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, + }, +}; /* * @pre pdev != NULL; @@ -51,23 +63,36 @@ static bool is_allocated_to_prelaunched_vm(struct pci_pdev *pdev) */ void fill_pci_dev_config(struct pci_pdev *pdev) { + uint16_t vmid; + uint32_t idx; + struct acrn_vm_config *vm_config; struct acrn_vm_pci_dev_config *dev_config; if (!is_allocated_to_prelaunched_vm(pdev)) { - dev_config = &pcidev_config[pcidev_config_num]; - dev_config->emu_type = (pdev->bdf.value != HOST_BRIDGE_BDF) ? PCI_DEV_TYPE_PTDEV : PCI_DEV_TYPE_HVEMUL; - dev_config->vbdf.value = pdev->bdf.value; - dev_config->pbdf.value = pdev->bdf.value; - dev_config->pdev = pdev; - pcidev_config_num++; + for (vmid = 0U; vmid < CONFIG_MAX_VM_NUM; vmid++) { + vm_config = get_vm_config(vmid); + if (vm_config->load_order != SOS_VM) { + continue; + } + + /* TODO: revert me if we could split post-launched VM's PTDev from SOS's */ + for (idx = 0U; idx < SOS_EMULATED_PCI_DEV_NUM; idx++) { + dev_config = &vm_config->pci_devs[idx]; + if (bdf_is_equal(&dev_config->pbdf, &pdev->bdf)) { + dev_config->pdev = pdev; + break; + } + + } + + if (idx == SOS_EMULATED_PCI_DEV_NUM) { + dev_config = &vm_config->pci_devs[vm_config->pci_dev_num]; + dev_config->emu_type = PCI_DEV_TYPE_PTDEV; + dev_config->vbdf.value = pdev->bdf.value; + dev_config->pbdf.value = pdev->bdf.value; + dev_config->pdev = pdev; + vm_config->pci_dev_num++; + } + } } } - -/* - * @pre vm_config != NULL - */ -void initialize_sos_pci_dev_config(struct acrn_vm_config *vm_config) -{ - vm_config->pci_dev_num = pcidev_config_num; - vm_config->pci_devs = pcidev_config; -} diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 49410024b..1615fac02 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -448,8 +448,6 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_ status = init_vm_boot_info(vm); if (status != 0) { need_cleanup = true; - } else { - initialize_sos_pci_dev_config(vm_config); } } else { /* For PRE_LAUNCHED_VM and POST_LAUNCHED_VM */ diff --git a/hypervisor/include/arch/x86/pci_dev.h b/hypervisor/include/arch/x86/pci_dev.h index c303c6fda..0306ad975 100644 --- a/hypervisor/include/arch/x86/pci_dev.h +++ b/hypervisor/include/arch/x86/pci_dev.h @@ -7,11 +7,13 @@ #ifndef PCI_DEV_H_ #define PCI_DEV_H_ -#include +#include -struct acrn_vm_config; +#define SOS_EMULATED_PCI_DEV_NUM 1U +extern struct acrn_vm_pci_dev_config sos_pci_devs[CONFIG_MAX_PCI_DEV_NUM]; + +struct pci_pdev; void fill_pci_dev_config(struct pci_pdev *pdev); -void initialize_sos_pci_dev_config(struct acrn_vm_config *vm_config); #endif /* PCI_DEV_H_ */ diff --git a/hypervisor/scenarios/hybrid/vm_configurations.c b/hypervisor/scenarios/hybrid/vm_configurations.c index f2caad6c0..855a761ba 100644 --- a/hypervisor/scenarios/hybrid/vm_configurations.c +++ b/hypervisor/scenarios/hybrid/vm_configurations.c @@ -6,6 +6,7 @@ #include #include +#include struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { { /* VM0 */ @@ -41,6 +42,8 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .t_vuart.vm_id = 1U, .t_vuart.vuart_id = 1U, }, + .pci_dev_num = SOS_EMULATED_PCI_DEV_NUM, + .pci_devs = sos_pci_devs, }, { /* VM1 */ .load_order = SOS_VM, diff --git a/hypervisor/scenarios/industry/vm_configurations.c b/hypervisor/scenarios/industry/vm_configurations.c index 3747ca0fa..c771803c3 100644 --- a/hypervisor/scenarios/industry/vm_configurations.c +++ b/hypervisor/scenarios/industry/vm_configurations.c @@ -6,6 +6,7 @@ #include #include +#include struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { { @@ -34,7 +35,9 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .vuart[1] = { .type = VUART_LEGACY_PIO, .addr.port_base = INVALID_COM_BASE, - } + }, + .pci_dev_num = SOS_EMULATED_PCI_DEV_NUM, + .pci_devs = sos_pci_devs, }, { .load_order = POST_LAUNCHED_VM, diff --git a/hypervisor/scenarios/logical_partition/pt_dev.c b/hypervisor/scenarios/logical_partition/pci_dev.c similarity index 88% rename from hypervisor/scenarios/logical_partition/pt_dev.c rename to hypervisor/scenarios/logical_partition/pci_dev.c index 0c0bfe344..ac0aed08a 100644 --- a/hypervisor/scenarios/logical_partition/pt_dev.c +++ b/hypervisor/scenarios/logical_partition/pci_dev.c @@ -12,7 +12,7 @@ * The memory range of vBAR should exactly match with the e820 layout of VM. */ -struct acrn_vm_pci_dev_config vm0_pci_devs[VM0_CONFIG_PCI_PTDEV_NUM] = { +struct acrn_vm_pci_dev_config vm0_pci_devs[VM0_CONFIG_PCI_DEV_NUM] = { { .emu_type = PCI_DEV_TYPE_HVEMUL, .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, @@ -29,7 +29,7 @@ struct acrn_vm_pci_dev_config vm0_pci_devs[VM0_CONFIG_PCI_PTDEV_NUM] = { }, }; -struct acrn_vm_pci_dev_config vm1_pci_devs[VM1_CONFIG_PCI_PTDEV_NUM] = { +struct acrn_vm_pci_dev_config vm1_pci_devs[VM1_CONFIG_PCI_DEV_NUM] = { { .emu_type = PCI_DEV_TYPE_HVEMUL, .vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U}, diff --git a/hypervisor/scenarios/logical_partition/vm_configurations.c b/hypervisor/scenarios/logical_partition/vm_configurations.c index 1dab5c991..d5729a152 100644 --- a/hypervisor/scenarios/logical_partition/vm_configurations.c +++ b/hypervisor/scenarios/logical_partition/vm_configurations.c @@ -7,8 +7,8 @@ #include #include -extern struct acrn_vm_pci_dev_config vm0_pci_devs[VM0_CONFIG_PCI_PTDEV_NUM]; -extern struct acrn_vm_pci_dev_config vm1_pci_devs[VM1_CONFIG_PCI_PTDEV_NUM]; +extern struct acrn_vm_pci_dev_config vm0_pci_devs[VM0_CONFIG_PCI_DEV_NUM]; +extern struct acrn_vm_pci_dev_config vm1_pci_devs[VM1_CONFIG_PCI_DEV_NUM]; struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { { /* VM0 */ @@ -46,7 +46,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .t_vuart.vm_id = 1U, .t_vuart.vuart_id = 1U, }, - .pci_dev_num = VM0_CONFIG_PCI_PTDEV_NUM, + .pci_dev_num = VM0_CONFIG_PCI_DEV_NUM, .pci_devs = vm0_pci_devs, }, { /* VM1 */ @@ -85,7 +85,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .t_vuart.vm_id = 0U, .t_vuart.vuart_id = 1U, }, - .pci_dev_num = VM1_CONFIG_PCI_PTDEV_NUM, + .pci_dev_num = VM1_CONFIG_PCI_DEV_NUM, .pci_devs = vm1_pci_devs, }, }; diff --git a/hypervisor/scenarios/logical_partition/vm_configurations.h b/hypervisor/scenarios/logical_partition/vm_configurations.h index c0f8d90c4..f46fd1e6b 100644 --- a/hypervisor/scenarios/logical_partition/vm_configurations.h +++ b/hypervisor/scenarios/logical_partition/vm_configurations.h @@ -45,7 +45,7 @@ */ #define VM0_STORAGE_CONTROLLER SATA_CONTROLLER_0 #define VM0_NETWORK_CONTROLLER ETHERNET_CONTROLLER_0 -#define VM0_CONFIG_PCI_PTDEV_NUM 3U +#define VM0_CONFIG_PCI_DEV_NUM 3U #define VM1_STORAGE_CONTROLLER USB_CONTROLLER_0 #if defined(ETHERNET_CONTROLLER_1) @@ -57,10 +57,10 @@ #endif #if defined(VM1_NETWORK_CONTROLLER) -#define VM1_CONFIG_PCI_PTDEV_NUM 3U +#define VM1_CONFIG_PCI_DEV_NUM 3U #else /* no network controller could be assigned to VM1 */ -#define VM1_CONFIG_PCI_PTDEV_NUM 2U +#define VM1_CONFIG_PCI_DEV_NUM 2U #endif #endif /* VM_CONFIGURATIONS_H */ diff --git a/hypervisor/scenarios/sdc/vm_configurations.c b/hypervisor/scenarios/sdc/vm_configurations.c index fcc0559d8..e0969b9e5 100644 --- a/hypervisor/scenarios/sdc/vm_configurations.c +++ b/hypervisor/scenarios/sdc/vm_configurations.c @@ -6,6 +6,7 @@ #include #include +#include struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { { @@ -36,7 +37,9 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .vuart[1] = { .type = VUART_LEGACY_PIO, .addr.port_base = INVALID_COM_BASE, - } + }, + .pci_dev_num = SOS_EMULATED_PCI_DEV_NUM, + .pci_devs = sos_pci_devs, }, { .load_order = POST_LAUNCHED_VM, diff --git a/hypervisor/scenarios/sdc2/vm_configurations.c b/hypervisor/scenarios/sdc2/vm_configurations.c index ddd308517..b64f7cbe3 100644 --- a/hypervisor/scenarios/sdc2/vm_configurations.c +++ b/hypervisor/scenarios/sdc2/vm_configurations.c @@ -6,6 +6,7 @@ #include #include +#include struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { { @@ -36,7 +37,9 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .vuart[1] = { .type = VUART_LEGACY_PIO, .addr.port_base = INVALID_COM_BASE, - } + }, + .pci_dev_num = SOS_EMULATED_PCI_DEV_NUM, + .pci_devs = sos_pci_devs, }, { .load_order = POST_LAUNCHED_VM,