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