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