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