]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Include/Library/CcExitLib.h
OvmfPkg/UefiCpuPkg: Add CcExit prefix to the APIs of CcExitLib
[mirror_edk2.git] / UefiCpuPkg / Include / Library / CcExitLib.h
1 /** @file
2 Public header file for the CcExitLib.
3
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
6 #VC exceptions.
7 - Handle #VE exception in TDX.
8
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
12
13 **/
14
15 #ifndef CC_EXIT_LIB_H_
16 #define CC_EXIT_LIB_H_
17
18 #include <Protocol/DebugSupport.h>
19 #include <Register/Amd/Ghcb.h>
20
21 #define VE_EXCEPTION 20
22
23 /**
24 Perform VMGEXIT.
25
26 Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and
27 then handles the return actions.
28
29 @param[in, out] Ghcb A pointer to the GHCB
30 @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode
31 field of the GHCB.
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.
36
37 @retval 0 VMGEXIT succeeded.
38 @return Exception number to be propagated, VMGEXIT
39 processing did not succeed.
40
41 **/
42 UINT64
43 EFIAPI
44 CcExitVmgExit (
45 IN OUT GHCB *Ghcb,
46 IN UINT64 ExitCode,
47 IN UINT64 ExitInfo1,
48 IN UINT64 ExitInfo2
49 );
50
51 /**
52 Perform pre-VMGEXIT initialization/preparation.
53
54 Performs the necessary steps in preparation for invoking VMGEXIT. Must be
55 called before setting any fields within the GHCB.
56
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 ()
60
61 **/
62 VOID
63 EFIAPI
64 CcExitVmgInit (
65 IN OUT GHCB *Ghcb,
66 IN OUT BOOLEAN *InterruptState
67 );
68
69 /**
70 Perform post-VMGEXIT cleanup.
71
72 Performs the necessary steps to cleanup after invoking VMGEXIT. Must be
73 called after obtaining needed fields within the GHCB.
74
75 @param[in, out] Ghcb A pointer to the GHCB
76 @param[in] InterruptState An indicator to conditionally (re)enable
77 interrupts
78
79 **/
80 VOID
81 EFIAPI
82 CcExitVmgDone (
83 IN OUT GHCB *Ghcb,
84 IN BOOLEAN InterruptState
85 );
86
87 /**
88 Marks a specified offset as valid in the GHCB.
89
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.
92
93 @param[in, out] Ghcb A pointer to the GHCB
94 @param[in] Offset Qword offset in the GHCB to mark valid
95
96 **/
97 VOID
98 EFIAPI
99 CcExitVmgSetOffsetValid (
100 IN OUT GHCB *Ghcb,
101 IN GHCB_REGISTER Offset
102 );
103
104 /**
105 Checks if a specified offset is valid in the GHCB.
106
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.
109
110 @param[in] Ghcb A pointer to the GHCB
111 @param[in] Offset Qword offset in the GHCB to mark valid
112
113 @retval TRUE Offset is marked valid in the GHCB
114 @retval FALSE Offset is not marked valid in the GHCB
115
116 **/
117 BOOLEAN
118 EFIAPI
119 CcExitVmgIsOffsetValid (
120 IN GHCB *Ghcb,
121 IN GHCB_REGISTER Offset
122 );
123
124 /**
125 Handle a #VC exception.
126
127 Performs the necessary processing to handle a #VC exception.
128
129 The base library function returns an error equal to VC_EXCEPTION,
130 to be propagated to the standard exception handling stack.
131
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
135
136 @retval EFI_SUCCESS Exception handled
137 @retval EFI_UNSUPPORTED #VC not supported, (new) exception value to
138 propagate provided
139 @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception value to
140 propagate provided
141
142 **/
143 EFI_STATUS
144 EFIAPI
145 CcExitHandleVc (
146 IN OUT EFI_EXCEPTION_TYPE *ExceptionType,
147 IN OUT EFI_SYSTEM_CONTEXT SystemContext
148 );
149
150 /**
151 Handle a #VE exception.
152
153 Performs the necessary processing to handle a #VE exception.
154
155 The base library function returns an error equal to VE_EXCEPTION,
156 to be propagated to the standard exception handling stack.
157
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
161
162 @retval EFI_SUCCESS Exception handled
163 @retval EFI_UNSUPPORTED #VE not supported, (new) exception value to
164 propagate provided
165 @retval EFI_PROTOCOL_ERROR #VE handling failed, (new) exception value to
166 propagate provided
167
168 **/
169 EFI_STATUS
170 EFIAPI
171 CcExitHandleVe (
172 IN OUT EFI_EXCEPTION_TYPE *ExceptionType,
173 IN OUT EFI_SYSTEM_CONTEXT SystemContext
174 );
175
176 #endif