From 8f0cb5630d9501c54da40c1ee02eab80ffecca36 Mon Sep 17 00:00:00 2001 From: Qi Yadong Date: Mon, 17 Sep 2018 15:32:08 +0800 Subject: [PATCH] HV: trusty: refine version checking when initializing trusty Replace if--else logic with switch--case when checking interface version. Tracked-On: #1265 Signed-off-by: Qi Yadong Acked-by: Zhu Bing --- hypervisor/arch/x86/trusty.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/hypervisor/arch/x86/trusty.c b/hypervisor/arch/x86/trusty.c index a1ab8125d..ee429a5ea 100644 --- a/hypervisor/arch/x86/trusty.c +++ b/hypervisor/arch/x86/trusty.c @@ -417,28 +417,30 @@ bool initialize_trusty(struct vcpu *vcpu, uint64_t param) return false; } - if (boot_param.version > TRUSTY_VERSION_2) { - dev_dbg(ACRN_DBG_TRUSTY, "%s: Version(%u) not supported!\n", - __func__, boot_param.version); - return false; - } - - trusty_entry_gpa = (uint64_t)boot_param.entry_point; - trusty_base_gpa = (uint64_t)boot_param.base_addr; - trusty_mem_size = boot_param.mem_size; - - if (boot_param.version >= TRUSTY_VERSION_2) { - trusty_entry_gpa |= + switch (boot_param.version) { + case TRUSTY_VERSION_2: + trusty_entry_gpa = ((uint64_t)boot_param.entry_point) | (((uint64_t)boot_param.entry_point_high) << 32); - trusty_base_gpa |= + trusty_base_gpa = ((uint64_t)boot_param.base_addr) | (((uint64_t)boot_param.base_addr_high) << 32); /* copy rpmb_key from OSloader */ (void)memcpy_s(&g_key_info.rpmb_key[0][0], 64U, &boot_param.rpmb_key[0], 64U); (void)memset(&boot_param.rpmb_key[0], 0U, 64U); + break; + case TRUSTY_VERSION: + trusty_entry_gpa = (uint64_t)boot_param.entry_point; + trusty_base_gpa = (uint64_t)boot_param.base_addr; + break; + default: + dev_dbg(ACRN_DBG_TRUSTY, "%s: Version(%u) not supported!\n", + __func__, boot_param.version); + return false; } + trusty_mem_size = boot_param.mem_size; + create_secure_world_ept(vm, trusty_base_gpa, trusty_mem_size, TRUSTY_EPT_REBASE_GPA); trusty_base_hpa = vm->sworld_control.sworld_memory.base_hpa;