--- /dev/null
+/** @file\r
+ Public header file for the VMGEXIT Support library class.\r
+\r
+ This library class defines some routines used when invoking the VMGEXIT\r
+ instruction in support of SEV-ES and to handle #VC exceptions.\r
+\r
+ Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef __VMG_EXIT_LIB_H__\r
+#define __VMG_EXIT_LIB_H__\r
+\r
+#include <Protocol/DebugSupport.h>\r
+#include <Register/Amd/Ghcb.h>\r
+\r
+\r
+/**\r
+ Perform VMGEXIT.\r
+\r
+ Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and\r
+ then handles the return actions.\r
+\r
+ @param[in, out] Ghcb A pointer to the GHCB\r
+ @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode\r
+ field of the GHCB.\r
+ @param[in] ExitInfo1 VMGEXIT information to be assigned to the\r
+ SwExitInfo1 field of the GHCB.\r
+ @param[in] ExitInfo2 VMGEXIT information to be assigned to the\r
+ SwExitInfo2 field of the GHCB.\r
+\r
+ @retval 0 VMGEXIT succeeded.\r
+ @return Exception number to be propagated, VMGEXIT\r
+ processing did not succeed.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+VmgExit (\r
+ IN OUT GHCB *Ghcb,\r
+ IN UINT64 ExitCode,\r
+ IN UINT64 ExitInfo1,\r
+ IN UINT64 ExitInfo2\r
+ );\r
+\r
+/**\r
+ Perform pre-VMGEXIT initialization/preparation.\r
+\r
+ Performs the necessary steps in preparation for invoking VMGEXIT. Must be\r
+ called before setting any fields within the GHCB.\r
+\r
+ @param[in, out] Ghcb A pointer to the GHCB\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+VmgInit (\r
+ IN OUT GHCB *Ghcb\r
+ );\r
+\r
+/**\r
+ Perform post-VMGEXIT cleanup.\r
+\r
+ Performs the necessary steps to cleanup after invoking VMGEXIT. Must be\r
+ called after obtaining needed fields within the GHCB.\r
+\r
+ @param[in, out] Ghcb A pointer to the GHCB\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+VmgDone (\r
+ IN OUT GHCB *Ghcb\r
+ );\r
+\r
+/**\r
+ Handle a #VC exception.\r
+\r
+ Performs the necessary processing to handle a #VC exception.\r
+\r
+ The base library function returns an error equal to VC_EXCEPTION,\r
+ to be propagated to the standard exception handling stack.\r
+\r
+ @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set\r
+ as value to use on error.\r
+ @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT\r
+\r
+ @retval EFI_SUCCESS Exception handled\r
+ @retval EFI_UNSUPPORTED #VC not supported, (new) exception value to\r
+ propagate provided\r
+ @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception value to\r
+ propagate provided\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VmgExitHandleVc (\r
+ IN OUT EFI_EXCEPTION_TYPE *ExceptionType,\r
+ IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
+ );\r
+\r
+#endif\r
--- /dev/null
+/** @file\r
+ VMGEXIT Base Support Library.\r
+\r
+ Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+#include <Uefi.h>\r
+#include <Library/VmgExitLib.h>\r
+\r
+/**\r
+ Perform VMGEXIT.\r
+\r
+ Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and\r
+ then handles the return actions.\r
+\r
+ The base library function returns an error in the form of a\r
+ GHCB_EVENT_INJECTION representing a GP_EXCEPTION.\r
+\r
+ @param[in, out] Ghcb A pointer to the GHCB\r
+ @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode\r
+ field of the GHCB.\r
+ @param[in] ExitInfo1 VMGEXIT information to be assigned to the\r
+ SwExitInfo1 field of the GHCB.\r
+ @param[in] ExitInfo2 VMGEXIT information to be assigned to the\r
+ SwExitInfo2 field of the GHCB.\r
+\r
+ @retval 0 VMGEXIT succeeded.\r
+ @return Exception number to be propagated, VMGEXIT\r
+ processing did not succeed.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+VmgExit (\r
+ IN OUT GHCB *Ghcb,\r
+ IN UINT64 ExitCode,\r
+ IN UINT64 ExitInfo1,\r
+ IN UINT64 ExitInfo2\r
+ )\r
+{\r
+ GHCB_EVENT_INJECTION Event;\r
+\r
+ Event.Uint64 = 0;\r
+ Event.Elements.Vector = GP_EXCEPTION;\r
+ Event.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;\r
+ Event.Elements.Valid = 1;\r
+\r
+ return Event.Uint64;\r
+}\r
+\r
+/**\r
+ Perform pre-VMGEXIT initialization/preparation.\r
+\r
+ Performs the necessary steps in preparation for invoking VMGEXIT. Must be\r
+ called before setting any fields within the GHCB.\r
+\r
+ The base library function does nothing.\r
+\r
+ @param[in, out] Ghcb A pointer to the GHCB\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+VmgInit (\r
+ IN OUT GHCB *Ghcb\r
+ )\r
+{\r
+}\r
+\r
+/**\r
+ Perform post-VMGEXIT cleanup.\r
+\r
+ Performs the necessary steps to cleanup after invoking VMGEXIT. Must be\r
+ called after obtaining needed fields within the GHCB.\r
+\r
+ The base library function does nothing.\r
+\r
+ @param[in, out] Ghcb A pointer to the GHCB\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+VmgDone (\r
+ IN OUT GHCB *Ghcb\r
+ )\r
+{\r
+}\r
+\r
+/**\r
+ Handle a #VC exception.\r
+\r
+ Performs the necessary processing to handle a #VC exception.\r
+\r
+ The base library function returns an error equal to VC_EXCEPTION,\r
+ to be propagated to the standard exception handling stack.\r
+\r
+ @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set\r
+ as value to use on error.\r
+ @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT\r
+\r
+ @retval EFI_SUCCESS Exception handled\r
+ @retval EFI_UNSUPPORTED #VC not supported, (new) exception value to\r
+ propagate provided\r
+ @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception value to\r
+ propagate provided\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VmgExitHandleVc (\r
+ IN OUT EFI_EXCEPTION_TYPE *ExceptionType,\r
+ IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
+ )\r
+{\r
+ *ExceptionType = VC_EXCEPTION;\r
+\r
+ return EFI_UNSUPPORTED;\r
+}\r
--- /dev/null
+## @file\r
+# VMGEXIT Support Library.\r
+#\r
+# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = VmgExitLibNull\r
+ MODULE_UNI_FILE = VmgExitLibNull.uni\r
+ FILE_GUID = 3cd7368f-ef9b-4a9b-9571-2ed93813677e\r
+ MODULE_TYPE = BASE\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = VmgExitLib\r
+\r
+[Sources.common]\r
+ VmgExitLibNull.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ UefiCpuPkg/UefiCpuPkg.dec\r
+\r
+[LibraryClasses]\r
+ BaseLib\r
+\r
--- /dev/null
+// /** @file\r
+// VMGEXIT support library instance.\r
+//\r
+// VMGEXIT support library instance.\r
+//\r
+// Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>\r
+// SPDX-License-Identifier: BSD-2-Clause-Patent\r
+//\r
+// **/\r
+\r
+\r
+#string STR_MODULE_ABSTRACT #language en-US "VMGEXIT support NULL library instance"\r
+\r
+#string STR_MODULE_DESCRIPTION #language en-US "VMGEXIT support NULL library instance."\r
+\r
##\r
MpInitLib|Include/Library/MpInitLib.h\r
\r
+ ## @libraryclass Provides function to support VMGEXIT processing.\r
+ VmgExitLib|Include/Library/VmgExitLib.h\r
+\r
[Guids]\r
gUefiCpuPkgTokenSpaceGuid = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa, 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}\r
gMsegSmramGuid = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1, 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }}\r
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf\r
PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf\r
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf\r
+ VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf\r
\r
[LibraryClasses.common.SEC]\r
PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf\r
UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.inf\r
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf\r
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf\r
+ UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf\r
UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf\r
UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf\r
UefiCpuPkg/SecCore/SecCore.inf\r