diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index bccd2a477..2140d2ee1 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -639,6 +639,10 @@ static void cpu_secondary_post(void) exec_vmxon_instr(get_cpu_id()); +#ifdef CONFIG_PARTITION_MODE + prepare_vm(get_cpu_id()); +#endif + default_idle(); /* Control will only come here for secondary diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index f67904fe7..6c4988bbd 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -404,6 +404,40 @@ void resume_vm_from_s3(struct vm *vm, uint32_t wakeup_vec) schedule_vcpu(bsp); } +#ifdef CONFIG_PARTITION_MODE +/* Create vm/vcpu for vm */ +int prepare_vm(uint16_t pcpu_id) +{ + int ret = 0; + uint16_t i; + struct vm *vm = NULL; + const struct vm_description *vm_desc = NULL; + bool is_vm_bsp; + + vm_desc = pcpu_vm_desc_map[pcpu_id].vm_desc_ptr; + is_vm_bsp = pcpu_vm_desc_map[pcpu_id].is_bsp; + + if (is_vm_bsp) { + ret = create_vm(vm_desc, &vm); + ASSERT(ret == 0, "VM creation failed!"); + + prepare_vcpu(vm, vm_desc->vm_pcpu_ids[0]); + + /* Prepare the AP for vm */ + for (i = 1U; i < vm_desc->vm_hw_num_cores; i++) + prepare_vcpu(vm, vm_desc->vm_pcpu_ids[i]); + + /* start vm BSP automatically */ + start_vm(vm); + + pr_acrnlog("Start VM%x", vm_desc->vm_id); + } + + return ret; +} + +#else + /* Create vm/vcpu for vm0 */ int prepare_vm0(void) { @@ -448,6 +482,7 @@ int prepare_vm(uint16_t pcpu_id) return err; } +#endif #ifdef CONFIG_VM0_DESC static inline bool vcpu_in_vm_desc(struct vcpu *vcpu, diff --git a/hypervisor/bsp/sbl/vm_description.c b/hypervisor/bsp/sbl/vm_description.c index c3db2cff2..d94c05ea3 100644 --- a/hypervisor/bsp/sbl/vm_description.c +++ b/hypervisor/bsp/sbl/vm_description.c @@ -6,7 +6,7 @@ #include -#ifdef CONFIG_VM0_DESC +#if defined(CONFIG_VM0_DESC) && !defined(CONFIG_PARTITION_MODE) /* Number of CPUs in VM0 */ #define VM0_NUM_CPUS 1 @@ -24,3 +24,79 @@ struct vm_description vm0_desc = { struct vm_description vm0_desc; #endif // CONFIG_VM0_DESC + +#ifdef CONFIG_PARTITION_MODE + +#define NUM_USER_VMS 2U + +/**********************/ +/* VIRTUAL MACHINE 0 */ +/*********************/ + +/* Number of CPUs in this VM*/ +#define VM1_NUM_CPUS 2U + +/* Logical CPU IDs assigned to this VM */ +int VM1_CPUS[VM1_NUM_CPUS] = {0U, 2U}; + +/*********************/ +/* VIRTUAL MACHINE 1 */ +/*********************/ + +/* Number of CPUs in this VM*/ +#define VM2_NUM_CPUS 2U + +/* Logical CPU IDs assigned with this VM */ +int VM2_CPUS[VM2_NUM_CPUS] = {3U, 1U}; + + +/*******************************/ +/* User Defined VM definitions */ +/*******************************/ +const struct vm_description_array vm_desc_mrb = { + /* Number of user virtual machines */ + .num_vm_desc = NUM_USER_VMS, + + /* Virtual Machine descriptions */ + .vm_desc_array = { + { + /* Internal variable, MUSTBE init to -1 */ + .vm_hw_num_cores = VM1_NUM_CPUS, + .vm_pcpu_ids = &VM1_CPUS[0], + .vm_id = 1U, + .bootargs = "root=/dev/sda rw rootwait noxsave maxcpus=2 nohpet console=hvc0 \ + console=ttyS0 no_timer_check ignore_loglevel log_buf_len=16M \ + consoleblank=0 tsc=reliable" + }, + + { + /* Internal variable, MUSTBE init to -1 */ + .vm_hw_num_cores = VM2_NUM_CPUS, + .vm_pcpu_ids = &VM2_CPUS[0], + .vm_id = 2U, + .bootargs = "root=/dev/sda rw rootwait noxsave maxcpus=2 nohpet console=hvc0 \ + console=ttyS0 no_timer_check ignore_loglevel log_buf_len=16M \ + consoleblank=0 tsc=reliable" + }, + } +}; + +const struct pcpu_vm_desc_mapping pcpu_vm_desc_map[] = { + { + .vm_desc_ptr = &vm_desc_mrb.vm_desc_array[0], + .is_bsp = true, + }, + { + .vm_desc_ptr = &vm_desc_mrb.vm_desc_array[1], + .is_bsp = false, + }, + { + .vm_desc_ptr = &vm_desc_mrb.vm_desc_array[0], + .is_bsp = false, + }, + { + .vm_desc_ptr = &vm_desc_mrb.vm_desc_array[1], + .is_bsp = true, + }, +}; +#endif diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index df374507d..af46910a3 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -170,7 +170,9 @@ struct vm_description { /* Whether secure world is enabled for current VM. */ bool sworld_enabled; #ifdef CONFIG_PARTITION_MODE + uint8_t vm_id; struct mptable_info *mptable; + const char *bootargs; #endif }; @@ -191,4 +193,16 @@ struct vm *get_vm_from_vmid(uint16_t vm_id); extern struct list_head vm_list; extern spinlock_t vm_list_lock; +#ifdef CONFIG_PARTITION_MODE +struct vm_description_array { + int num_vm_desc; + const struct vm_description vm_desc_array[]; +}; + +struct pcpu_vm_desc_mapping { + const struct vm_descriptin *vm_desc_ptr; + bool is_bsp; +}; +extern const struct pcpu_vm_desc_mapping pcpu_vm_desc_map[]; +#endif #endif /* VM_H_ */