MdePkg: Introduce basic Tdx functions in BaseLib
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Introduce basic Tdx functions in BaseLib: - TdCall () - TdVmCall () - TdIsEnabled () Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Zhiguang Liu <zhiguang.liu@intel.com> Cc: Brijesh Singh <brijesh.singh@amd.com> Cc: Erdem Aktas <erdemaktas@google.com> Cc: James Bottomley <jejb@linux.ibm.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Min Xu <min.m.xu@intel.com>
This commit is contained in:
63
MdePkg/Library/BaseLib/X64/TdProbe.c
Normal file
63
MdePkg/Library/BaseLib/X64/TdProbe.c
Normal file
@ -0,0 +1,63 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2020-2021, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Register/Intel/Cpuid.h>
|
||||
|
||||
/**
|
||||
Probe if TD is enabled.
|
||||
|
||||
@return TRUE TD is enabled.
|
||||
@return FALSE TD is not enabled.
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
TdIsEnabled (
|
||||
)
|
||||
{
|
||||
UINT32 Eax;
|
||||
UINT32 Ebx;
|
||||
UINT32 Ecx;
|
||||
UINT32 Edx;
|
||||
UINT32 LargestEax;
|
||||
BOOLEAN TdEnabled;
|
||||
CPUID_VERSION_INFO_ECX CpuIdVersionInfoEcx;
|
||||
|
||||
TdEnabled = FALSE;
|
||||
|
||||
do {
|
||||
AsmCpuid (CPUID_SIGNATURE, &LargestEax, &Ebx, &Ecx, &Edx);
|
||||
|
||||
if ( (Ebx != CPUID_SIGNATURE_GENUINE_INTEL_EBX)
|
||||
|| (Edx != CPUID_SIGNATURE_GENUINE_INTEL_EDX)
|
||||
|| (Ecx != CPUID_SIGNATURE_GENUINE_INTEL_ECX))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, &CpuIdVersionInfoEcx.Uint32, NULL);
|
||||
if (CpuIdVersionInfoEcx.Bits.ParaVirtualized == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (LargestEax < CPUID_GUESTTD_RUNTIME_ENVIRONMENT) {
|
||||
break;
|
||||
}
|
||||
|
||||
AsmCpuidEx (CPUID_GUESTTD_RUNTIME_ENVIRONMENT, 0, &Eax, &Ebx, &Ecx, &Edx);
|
||||
if ( (Ebx != CPUID_GUESTTD_SIGNATURE_GENUINE_INTEL_EBX)
|
||||
|| (Edx != CPUID_GUESTTD_SIGNATURE_GENUINE_INTEL_EDX)
|
||||
|| (Ecx != CPUID_GUESTTD_SIGNATURE_GENUINE_INTEL_ECX))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
TdEnabled = TRUE;
|
||||
} while (FALSE);
|
||||
|
||||
return TdEnabled;
|
||||
}
|
Reference in New Issue
Block a user