Skip to content

Commit 8f0cb56

Browse files
YadongQilijinxia
authored andcommitted
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 <yadong.qi@intel.com> Acked-by: Zhu Bing <bing.zhu@intel.com>
1 parent 9d60220 commit 8f0cb56

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

hypervisor/arch/x86/trusty.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -417,28 +417,30 @@ bool initialize_trusty(struct vcpu *vcpu, uint64_t param)
417417
return false;
418418
}
419419

420-
if (boot_param.version > TRUSTY_VERSION_2) {
421-
dev_dbg(ACRN_DBG_TRUSTY, "%s: Version(%u) not supported!\n",
422-
__func__, boot_param.version);
423-
return false;
424-
}
425-
426-
trusty_entry_gpa = (uint64_t)boot_param.entry_point;
427-
trusty_base_gpa = (uint64_t)boot_param.base_addr;
428-
trusty_mem_size = boot_param.mem_size;
429-
430-
if (boot_param.version >= TRUSTY_VERSION_2) {
431-
trusty_entry_gpa |=
420+
switch (boot_param.version) {
421+
case TRUSTY_VERSION_2:
422+
trusty_entry_gpa = ((uint64_t)boot_param.entry_point) |
432423
(((uint64_t)boot_param.entry_point_high) << 32);
433-
trusty_base_gpa |=
424+
trusty_base_gpa = ((uint64_t)boot_param.base_addr) |
434425
(((uint64_t)boot_param.base_addr_high) << 32);
435426

436427
/* copy rpmb_key from OSloader */
437428
(void)memcpy_s(&g_key_info.rpmb_key[0][0], 64U,
438429
&boot_param.rpmb_key[0], 64U);
439430
(void)memset(&boot_param.rpmb_key[0], 0U, 64U);
431+
break;
432+
case TRUSTY_VERSION:
433+
trusty_entry_gpa = (uint64_t)boot_param.entry_point;
434+
trusty_base_gpa = (uint64_t)boot_param.base_addr;
435+
break;
436+
default:
437+
dev_dbg(ACRN_DBG_TRUSTY, "%s: Version(%u) not supported!\n",
438+
__func__, boot_param.version);
439+
return false;
440440
}
441441

442+
trusty_mem_size = boot_param.mem_size;
443+
442444
create_secure_world_ept(vm, trusty_base_gpa, trusty_mem_size,
443445
TRUSTY_EPT_REBASE_GPA);
444446
trusty_base_hpa = vm->sworld_control.sworld_memory.base_hpa;

0 commit comments

Comments
 (0)