From b8ccad5650aa576aed622d555f8dd1238e5230fa Mon Sep 17 00:00:00 2001 From: "Qi, Yadong" Date: Thu, 2 Apr 2020 14:52:33 +0800 Subject: [PATCH] cic: create callback event to activate VT-d in eVMM Create a callback event which will be triggered when ExitBootServices() is invoked. In this callback, KF will issue a vmcall to inform eVMM to activate VT-d. Signed-off-by: Qi, Yadong --- kf4cic.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/kf4cic.c b/kf4cic.c index 12e9aa06..afde047d 100755 --- a/kf4cic.c +++ b/kf4cic.c @@ -227,6 +227,31 @@ EFI_STATUS load_and_start_tos(EFI_HANDLE image) ret = start_trusty(tosimage); debug(L"start_trusty return: %r(%x)\n", ret, ret); + + return ret; +} + +static VOID EFI_API activate_vtd_vmcall(EFI_EVENT event, VOID *ctx) +{ + (void)event; + (void)ctx; +#define VMCALL_ACTIVATE_VTD 0x56544400ULL // "VTD" + asm volatile ("vmcall" : : "a"(VMCALL_ACTIVATE_VTD)); +} + +static EFI_STATUS create_vtd_activate_event(VOID) +{ + EFI_EVENT e; + ret = uefi_call_wrapper(BS->CreateEvent, + 5, + EVT_SIGNAL_EXIT_BOOT_SERVICES, + EFI_TPL_CALLBACK, + activate_vtd_vmcall, + NULL, + &e); + if (EFI_ERROR (ret)) { + debug(L"Failed to create callback event for VT-d activate in eVMM\n"); + } return ret; } #endif @@ -280,6 +305,11 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table) ret = load_and_start_tos(image); if (EFI_ERROR(ret)) return ret; + + debug(L"Create VT-d activate event...\n"); + ret = create_vtd_activate_event(); + if (EFI_ERROR(ret)) + return ret; #endif ret = start_systemd_boot(image);