]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Include/Library/CcExitLib.h
OvmfPkg/UefiCpuPkg: Add CcExit prefix to the APIs of CcExitLib
[mirror_edk2.git] / UefiCpuPkg / Include / Library / CcExitLib.h
CommitLineData
87149787 1/** @file\r
a89f558d 2 Public header file for the CcExitLib.\r
87149787 3\r
a89f558d
MX
4 This library class defines some routines used for below CcExit handler.\r
5 - Invoking the VMGEXIT instruction in support of SEV-ES and to handle\r
6 #VC exceptions.\r
7 - Handle #VE exception in TDX.\r
87149787
TL
8\r
9 Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>\r
a89f558d 10 Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.<BR>\r
87149787
TL
11 SPDX-License-Identifier: BSD-2-Clause-Patent\r
12\r
13**/\r
14\r
a89f558d
MX
15#ifndef CC_EXIT_LIB_H_\r
16#define CC_EXIT_LIB_H_\r
87149787
TL
17\r
18#include <Protocol/DebugSupport.h>\r
19#include <Register/Amd/Ghcb.h>\r
20\r
eddcba40
MX
21#define VE_EXCEPTION 20\r
22\r
87149787
TL
23/**\r
24 Perform VMGEXIT.\r
25\r
26 Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and\r
27 then handles the return actions.\r
28\r
29 @param[in, out] Ghcb A pointer to the GHCB\r
30 @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode\r
31 field of the GHCB.\r
32 @param[in] ExitInfo1 VMGEXIT information to be assigned to the\r
33 SwExitInfo1 field of the GHCB.\r
34 @param[in] ExitInfo2 VMGEXIT information to be assigned to the\r
35 SwExitInfo2 field of the GHCB.\r
36\r
37 @retval 0 VMGEXIT succeeded.\r
38 @return Exception number to be propagated, VMGEXIT\r
39 processing did not succeed.\r
40\r
41**/\r
42UINT64\r
43EFIAPI\r
765ba5bf 44CcExitVmgExit (\r
053e878b
MK
45 IN OUT GHCB *Ghcb,\r
46 IN UINT64 ExitCode,\r
47 IN UINT64 ExitInfo1,\r
48 IN UINT64 ExitInfo2\r
87149787
TL
49 );\r
50\r
51/**\r
52 Perform pre-VMGEXIT initialization/preparation.\r
53\r
54 Performs the necessary steps in preparation for invoking VMGEXIT. Must be\r
55 called before setting any fields within the GHCB.\r
56\r
1b0db1ec
TL
57 @param[in, out] Ghcb A pointer to the GHCB\r
58 @param[in, out] InterruptState A pointer to hold the current interrupt\r
765ba5bf 59 state, used for restoring in CcExitVmgDone ()\r
87149787
TL
60\r
61**/\r
62VOID\r
63EFIAPI\r
765ba5bf 64CcExitVmgInit (\r
053e878b
MK
65 IN OUT GHCB *Ghcb,\r
66 IN OUT BOOLEAN *InterruptState\r
87149787
TL
67 );\r
68\r
69/**\r
70 Perform post-VMGEXIT cleanup.\r
71\r
72 Performs the necessary steps to cleanup after invoking VMGEXIT. Must be\r
73 called after obtaining needed fields within the GHCB.\r
74\r
1b0db1ec
TL
75 @param[in, out] Ghcb A pointer to the GHCB\r
76 @param[in] InterruptState An indicator to conditionally (re)enable\r
77 interrupts\r
87149787
TL
78\r
79**/\r
80VOID\r
81EFIAPI\r
765ba5bf 82CcExitVmgDone (\r
053e878b
MK
83 IN OUT GHCB *Ghcb,\r
84 IN BOOLEAN InterruptState\r
87149787
TL
85 );\r
86\r
8a7ca992
TL
87/**\r
88 Marks a specified offset as valid in the GHCB.\r
89\r
90 The ValidBitmap area represents the areas of the GHCB that have been marked\r
91 valid. Set the bit in ValidBitmap for the input offset.\r
92\r
93 @param[in, out] Ghcb A pointer to the GHCB\r
94 @param[in] Offset Qword offset in the GHCB to mark valid\r
95\r
96**/\r
97VOID\r
98EFIAPI\r
765ba5bf 99CcExitVmgSetOffsetValid (\r
053e878b
MK
100 IN OUT GHCB *Ghcb,\r
101 IN GHCB_REGISTER Offset\r
8a7ca992
TL
102 );\r
103\r
104/**\r
105 Checks if a specified offset is valid in the GHCB.\r
106\r
107 The ValidBitmap area represents the areas of the GHCB that have been marked\r
108 valid. Return whether the bit in the ValidBitmap is set for the input offset.\r
109\r
110 @param[in] Ghcb A pointer to the GHCB\r
111 @param[in] Offset Qword offset in the GHCB to mark valid\r
112\r
113 @retval TRUE Offset is marked valid in the GHCB\r
114 @retval FALSE Offset is not marked valid in the GHCB\r
115\r
116**/\r
117BOOLEAN\r
118EFIAPI\r
765ba5bf 119CcExitVmgIsOffsetValid (\r
053e878b
MK
120 IN GHCB *Ghcb,\r
121 IN GHCB_REGISTER Offset\r
8a7ca992
TL
122 );\r
123\r
87149787
TL
124/**\r
125 Handle a #VC exception.\r
126\r
127 Performs the necessary processing to handle a #VC exception.\r
128\r
129 The base library function returns an error equal to VC_EXCEPTION,\r
130 to be propagated to the standard exception handling stack.\r
131\r
132 @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set\r
133 as value to use on error.\r
134 @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT\r
135\r
136 @retval EFI_SUCCESS Exception handled\r
137 @retval EFI_UNSUPPORTED #VC not supported, (new) exception value to\r
138 propagate provided\r
139 @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception value to\r
140 propagate provided\r
141\r
142**/\r
143EFI_STATUS\r
144EFIAPI\r
765ba5bf 145CcExitHandleVc (\r
87149787
TL
146 IN OUT EFI_EXCEPTION_TYPE *ExceptionType,\r
147 IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
148 );\r
149\r
eddcba40
MX
150/**\r
151 Handle a #VE exception.\r
152\r
153 Performs the necessary processing to handle a #VE exception.\r
154\r
155 The base library function returns an error equal to VE_EXCEPTION,\r
156 to be propagated to the standard exception handling stack.\r
157\r
158 @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set\r
159 as value to use on error.\r
160 @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT\r
161\r
162 @retval EFI_SUCCESS Exception handled\r
163 @retval EFI_UNSUPPORTED #VE not supported, (new) exception value to\r
164 propagate provided\r
165 @retval EFI_PROTOCOL_ERROR #VE handling failed, (new) exception value to\r
166 propagate provided\r
167\r
168**/\r
169EFI_STATUS\r
170EFIAPI\r
765ba5bf 171CcExitHandleVe (\r
eddcba40
MX
172 IN OUT EFI_EXCEPTION_TYPE *ExceptionType,\r
173 IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
174 );\r
175\r
87149787 176#endif\r