2 Public header file for the CcExitLib.
4 This library class defines some routines used for below CcExit handler.
5 - Invoking the VMGEXIT instruction in support of SEV-ES and to handle
7 - Handle #VE exception in TDX.
9 Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
10 Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.<BR>
11 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #ifndef CC_EXIT_LIB_H_
16 #define CC_EXIT_LIB_H_
18 #include <Protocol/DebugSupport.h>
19 #include <Register/Amd/Ghcb.h>
21 #define VE_EXCEPTION 20
26 Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and
27 then handles the return actions.
29 @param[in, out] Ghcb A pointer to the GHCB
30 @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode
32 @param[in] ExitInfo1 VMGEXIT information to be assigned to the
33 SwExitInfo1 field of the GHCB.
34 @param[in] ExitInfo2 VMGEXIT information to be assigned to the
35 SwExitInfo2 field of the GHCB.
37 @retval 0 VMGEXIT succeeded.
38 @return Exception number to be propagated, VMGEXIT
39 processing did not succeed.
52 Perform pre-VMGEXIT initialization/preparation.
54 Performs the necessary steps in preparation for invoking VMGEXIT. Must be
55 called before setting any fields within the GHCB.
57 @param[in, out] Ghcb A pointer to the GHCB
58 @param[in, out] InterruptState A pointer to hold the current interrupt
59 state, used for restoring in CcExitVmgDone ()
66 IN OUT BOOLEAN
*InterruptState
70 Perform post-VMGEXIT cleanup.
72 Performs the necessary steps to cleanup after invoking VMGEXIT. Must be
73 called after obtaining needed fields within the GHCB.
75 @param[in, out] Ghcb A pointer to the GHCB
76 @param[in] InterruptState An indicator to conditionally (re)enable
84 IN BOOLEAN InterruptState
88 Marks a specified offset as valid in the GHCB.
90 The ValidBitmap area represents the areas of the GHCB that have been marked
91 valid. Set the bit in ValidBitmap for the input offset.
93 @param[in, out] Ghcb A pointer to the GHCB
94 @param[in] Offset Qword offset in the GHCB to mark valid
99 CcExitVmgSetOffsetValid (
101 IN GHCB_REGISTER Offset
105 Checks if a specified offset is valid in the GHCB.
107 The ValidBitmap area represents the areas of the GHCB that have been marked
108 valid. Return whether the bit in the ValidBitmap is set for the input offset.
110 @param[in] Ghcb A pointer to the GHCB
111 @param[in] Offset Qword offset in the GHCB to mark valid
113 @retval TRUE Offset is marked valid in the GHCB
114 @retval FALSE Offset is not marked valid in the GHCB
119 CcExitVmgIsOffsetValid (
121 IN GHCB_REGISTER Offset
125 Handle a #VC exception.
127 Performs the necessary processing to handle a #VC exception.
129 The base library function returns an error equal to VC_EXCEPTION,
130 to be propagated to the standard exception handling stack.
132 @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set
133 as value to use on error.
134 @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT
136 @retval EFI_SUCCESS Exception handled
137 @retval EFI_UNSUPPORTED #VC not supported, (new) exception value to
139 @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception value to
146 IN OUT EFI_EXCEPTION_TYPE
*ExceptionType
,
147 IN OUT EFI_SYSTEM_CONTEXT SystemContext
151 Handle a #VE exception.
153 Performs the necessary processing to handle a #VE exception.
155 The base library function returns an error equal to VE_EXCEPTION,
156 to be propagated to the standard exception handling stack.
158 @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set
159 as value to use on error.
160 @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT
162 @retval EFI_SUCCESS Exception handled
163 @retval EFI_UNSUPPORTED #VE not supported, (new) exception value to
165 @retval EFI_PROTOCOL_ERROR #VE handling failed, (new) exception value to
172 IN OUT EFI_EXCEPTION_TYPE
*ExceptionType
,
173 IN OUT EFI_SYSTEM_CONTEXT SystemContext