From a8e4f227ba879c5ea2957354e4af92211d82e515 Mon Sep 17 00:00:00 2001 From: Victor Sun Date: Thu, 17 Jan 2019 09:10:10 +0800 Subject: [PATCH] HV: add new acrn_vm_config member and config files - add new struct member for acrn_vm_config; - add sharing_config.c file with initialized vm_config array; - add SOS VM config header for apl-mrb/apl-nuc/up2 and dnv-cb2 board; - and partition_config.c file with dummy vm_config array; Tracked-On: #2291 Signed-off-by: Victor Sun Acked-by: Eddie Dong --- hypervisor/Makefile | 8 +++ hypervisor/arch/x86/configs/apl-mrb/sos_vm.h | 17 +++++++ hypervisor/arch/x86/configs/apl-nuc | 1 + hypervisor/arch/x86/configs/dnv-cb2/sos_vm.h | 17 +++++++ hypervisor/arch/x86/configs/nuc6cayh/sos_vm.h | 16 ++++++ .../arch/x86/configs/partition_config.c | 10 ++++ hypervisor/arch/x86/configs/sharing_config.c | 24 +++++++++ hypervisor/arch/x86/configs/up2/sos_vm.h | 17 +++++++ hypervisor/include/arch/x86/guest/vm.h | 49 ++++++++++++++++++- hypervisor/include/public/acrn_common.h | 4 +- 10 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 hypervisor/arch/x86/configs/apl-mrb/sos_vm.h create mode 120000 hypervisor/arch/x86/configs/apl-nuc create mode 100644 hypervisor/arch/x86/configs/dnv-cb2/sos_vm.h create mode 100644 hypervisor/arch/x86/configs/nuc6cayh/sos_vm.h create mode 100644 hypervisor/arch/x86/configs/partition_config.c create mode 100644 hypervisor/arch/x86/configs/sharing_config.c create mode 100644 hypervisor/arch/x86/configs/up2/sos_vm.h diff --git a/hypervisor/Makefile b/hypervisor/Makefile index 321e174ac..cedc17b21 100644 --- a/hypervisor/Makefile +++ b/hypervisor/Makefile @@ -109,6 +109,7 @@ INCLUDE_PATH += include/dm INCLUDE_PATH += bsp/include INCLUDE_PATH += boot/include INCLUDE_PATH += $(HV_OBJDIR)/include +INCLUDE_PATH += arch/x86/configs/$(CONFIG_BOARD) CC ?= gcc AS ?= as @@ -130,6 +131,13 @@ C_SRCS += boot/reloc.c # initilization component C_SRCS += arch/x86/init.c +# configuration component +ifeq ($(CONFIG_SHARING_MODE),y) +C_SRCS += arch/x86/configs/sharing_config.c +else ifeq ($(CONFIG_PARTITION_MODE),y) +C_SRCS += arch/x86/configs/partition_config.c +endif + C_SRCS += boot/acpi.c C_SRCS += boot/dmar_parse.c S_SRCS += arch/x86/idt.S diff --git a/hypervisor/arch/x86/configs/apl-mrb/sos_vm.h b/hypervisor/arch/x86/configs/apl-mrb/sos_vm.h new file mode 100644 index 000000000..7d0ca0ebe --- /dev/null +++ b/hypervisor/arch/x86/configs/apl-mrb/sos_vm.h @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2018 Intel Corporation. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef SOS_VM_CONFIG_H +#define SOS_VM_CONFIG_H + +#define SOS_VM_CONFIG_NAME "ACRN SOS VM for APL-MRB" +#define SOS_VM_CONFIG_MEM_SIZE 0x200000000UL +#define SOS_VM_CONFIG_PCPU_BITMAP (PLUG_CPU(0) | PLUG_CPU(1) | PLUG_CPU(2) | PLUG_CPU(3)) +#define SOS_VM_CONFIG_GUEST_FLAGS IO_COMPLETION_POLLING + +#define SOS_VM_CONFIG_OS_NAME "ClearLinux 26600" + +#endif /* SOS_VM_CONFIG_H */ diff --git a/hypervisor/arch/x86/configs/apl-nuc b/hypervisor/arch/x86/configs/apl-nuc new file mode 120000 index 000000000..92a6acd0b --- /dev/null +++ b/hypervisor/arch/x86/configs/apl-nuc @@ -0,0 +1 @@ +nuc6cayh \ No newline at end of file diff --git a/hypervisor/arch/x86/configs/dnv-cb2/sos_vm.h b/hypervisor/arch/x86/configs/dnv-cb2/sos_vm.h new file mode 100644 index 000000000..7cf41f09a --- /dev/null +++ b/hypervisor/arch/x86/configs/dnv-cb2/sos_vm.h @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2018 Intel Corporation. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#ifndef SOS_VM_CONFIG_H +#define SOS_VM_CONFIG_H + +#define SOS_VM_CONFIG_NAME "ACRN SOS VM for DNV-CB2" +#define SOS_VM_CONFIG_MEM_SIZE 0x400000000UL +#define SOS_VM_CONFIG_PCPU_BITMAP (PLUG_CPU(0) | PLUG_CPU(1) | PLUG_CPU(2) | PLUG_CPU(3) \ + | PLUG_CPU(4) | PLUG_CPU(5) | PLUG_CPU(6) | PLUG_CPU(7)) +#define SOS_VM_CONFIG_GUEST_FLAGS IO_COMPLETION_POLLING + +#define SOS_VM_CONFIG_OS_NAME "ClearLinux 26600" + +#endif /* SOS_VM_CONFIG_H */ diff --git a/hypervisor/arch/x86/configs/nuc6cayh/sos_vm.h b/hypervisor/arch/x86/configs/nuc6cayh/sos_vm.h new file mode 100644 index 000000000..19d8c06c3 --- /dev/null +++ b/hypervisor/arch/x86/configs/nuc6cayh/sos_vm.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2018 Intel Corporation. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#ifndef SOS_VM_CONFIG_H +#define SOS_VM_CONFIG_H + +#define SOS_VM_CONFIG_NAME "ACRN SOS VM for APL-NUC" +#define SOS_VM_CONFIG_MEM_SIZE 0x400000000UL +#define SOS_VM_CONFIG_PCPU_BITMAP (PLUG_CPU(0) | PLUG_CPU(1) | PLUG_CPU(2) | PLUG_CPU(3)) +#define SOS_VM_CONFIG_GUEST_FLAGS IO_COMPLETION_POLLING + +#define SOS_VM_CONFIG_OS_NAME "ClearLinux 26600" + +#endif /* SOS_VM_CONFIG_H */ diff --git a/hypervisor/arch/x86/configs/partition_config.c b/hypervisor/arch/x86/configs/partition_config.c new file mode 100644 index 000000000..b54d91371 --- /dev/null +++ b/hypervisor/arch/x86/configs/partition_config.c @@ -0,0 +1,10 @@ +/* + * Copyright (C) 2018 Intel Corporation. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] __aligned(PAGE_SIZE) = { +}; diff --git a/hypervisor/arch/x86/configs/sharing_config.c b/hypervisor/arch/x86/configs/sharing_config.c new file mode 100644 index 000000000..f42f48ec7 --- /dev/null +++ b/hypervisor/arch/x86/configs/sharing_config.c @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2018 Intel Corporation. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + +struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] __aligned(PAGE_SIZE) = { + { + .type = SOS_VM, + .name = SOS_VM_CONFIG_NAME, + .pcpu_bitmap = SOS_VM_CONFIG_PCPU_BITMAP, + .guest_flags = SOS_VM_CONFIG_GUEST_FLAGS, + .memory = { + .start_hpa = 0x0UL, + .size = SOS_VM_CONFIG_MEM_SIZE, + }, + .os_config = { + .name = SOS_VM_CONFIG_OS_NAME, + }, + }, +}; diff --git a/hypervisor/arch/x86/configs/up2/sos_vm.h b/hypervisor/arch/x86/configs/up2/sos_vm.h new file mode 100644 index 000000000..79cbb48a8 --- /dev/null +++ b/hypervisor/arch/x86/configs/up2/sos_vm.h @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2018 Intel Corporation. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef SOS_VM_CONFIG_H +#define SOS_VM_CONFIG_H + +#define SOS_VM_CONFIG_NAME "ACRN SOS VM for APL-UP2" +#define SOS_VM_CONFIG_MEM_SIZE 0x200000000UL +#define SOS_VM_CONFIG_PCPU_BITMAP (PLUG_CPU(0) | PLUG_CPU(1)) +#define SOS_VM_CONFIG_GUEST_FLAGS IO_COMPLETION_POLLING + +#define SOS_VM_CONFIG_OS_NAME "ClearLinux 26600" + +#endif /* SOS_VM_CONFIG_H */ diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index 244219820..1c031156a 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -22,6 +22,8 @@ enum vm_privilege_level { #define INVALID_VM_ID 0xffffU +#define PLUG_CPU(n) (1U << n) + struct vm_hw_info { /* vcpu array of this VM */ struct acrn_vcpu vcpu_array[CONFIG_MAX_VCPUS_PER_VM]; @@ -172,12 +174,52 @@ struct vpci_vdev_array { }; #endif +#define MAX_BOOTARGS_SIZE 1024U +#define MAX_CONFIG_NAME_SIZE 32U + +enum acrn_vm_type { + UNDEFINED_VM = 0, + PRE_LAUNCHED_VM, + SOS_VM, + NORMAL_VM, + /* PRIVILEGE_VM, */ +}; + +struct acrn_vm_mem_config { + uint64_t start_hpa; /* the start HPA of VM memory configuration, for pre-launched VMs only */ + uint64_t size; /* VM memory size configuration */ +}; + +struct acrn_vm_os_config { + char name[MAX_CONFIG_NAME_SIZE]; /* OS name, useful for debug */ + char bootargs[MAX_BOOTARGS_SIZE]; /* boot args/cmdline */ +} __aligned(8); + +struct acrn_vm_pci_ptdev_config { + union pci_bdf vbdf; /* virtual BDF of PCI PT device */ + union pci_bdf pbdf; /* physical BDF of PCI PT device */ +} __aligned(8); + struct acrn_vm_config { + enum acrn_vm_type type; /* specify the type of VM */ + char name[MAX_CONFIG_NAME_SIZE]; /* VM name identifier, useful for debug. */ + uint8_t GUID[16]; /* GUID of the VM */ + uint64_t pcpu_bitmap; /* from pcpu bitmap, we could know VM core number */ + uint64_t guest_flags; /* VM flags that we want to configure for guest + * Now we have two flags: + * SECURE_WORLD_ENABLED + * LAPIC_PASSTHROUGH + * We could add more guest flags in future; + */ + struct acrn_vm_mem_config memory; /* memory configuration of VM */ + uint16_t pci_ptdev_num; /* indicate how many PCI PT devices in VM */ + struct acrn_vm_pci_ptdev_config *pci_ptdevs; /* point to PCI PT devices BDF list */ + struct acrn_vm_os_config os_config; /* OS information the VM */ + /* The physical CPU IDs associated with this VM - The first CPU listed * will be the VM's BSP */ uint16_t *vm_pcpu_ids; - uint8_t GUID[16]; /* GUID of the vm will be created */ uint16_t vm_hw_num_cores; /* Number of virtual cores */ /* Whether secure world is supported for current VM. */ bool sworld_supported; @@ -191,7 +233,8 @@ struct acrn_vm_config { struct vpci_vdev_array *vpci_vdev_array; bool lapic_pt; #endif -}; + +} __aligned(8); static inline bool is_vm0(const struct acrn_vm *vm) { @@ -271,6 +314,8 @@ int32_t reset_vm(struct acrn_vm *vm); int32_t create_vm(struct acrn_vm_config *vm_config, struct acrn_vm **rtn_vm); int32_t prepare_vm(uint16_t pcpu_id); +extern struct acrn_vm_config vm_configs[]; + #ifdef CONFIG_PARTITION_MODE const struct vm_config_arraies *get_vm_config_base(void); #endif diff --git a/hypervisor/include/public/acrn_common.h b/hypervisor/include/public/acrn_common.h index bd31e32e8..b19437ae2 100644 --- a/hypervisor/include/public/acrn_common.h +++ b/hypervisor/include/public/acrn_common.h @@ -47,7 +47,9 @@ #endif /* Generic VM flags from guest OS */ -#define SECURE_WORLD_ENABLED (1UL << 0U) /* Whether secure world is enabled */ +#define SECURE_WORLD_ENABLED (1UL << 0U) /* Whether secure world is enabled */ +#define LAPIC_PASSTHROUGH (1UL << 1U) /* Whether LAPIC is passed through */ +#define IO_COMPLETION_POLLING (1UL << 2U) /* Whether need hypervisor poll IO completion */ /** * @brief Hypercall