]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
UefiCpuPkg: Implement library support for VMGEXIT
[mirror_edk2.git] / UefiCpuPkg / Library / VmgExitLibNull / VmgExitLibNull.c
1 /** @file
2 VMGEXIT Base Support Library.
3
4 Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Base.h>
10 #include <Uefi.h>
11 #include <Library/VmgExitLib.h>
12
13 /**
14 Perform VMGEXIT.
15
16 Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and
17 then handles the return actions.
18
19 The base library function returns an error in the form of a
20 GHCB_EVENT_INJECTION representing a GP_EXCEPTION.
21
22 @param[in, out] Ghcb A pointer to the GHCB
23 @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode
24 field of the GHCB.
25 @param[in] ExitInfo1 VMGEXIT information to be assigned to the
26 SwExitInfo1 field of the GHCB.
27 @param[in] ExitInfo2 VMGEXIT information to be assigned to the
28 SwExitInfo2 field of the GHCB.
29
30 @retval 0 VMGEXIT succeeded.
31 @return Exception number to be propagated, VMGEXIT
32 processing did not succeed.
33
34 **/
35 UINT64
36 EFIAPI
37 VmgExit (
38 IN OUT GHCB *Ghcb,
39 IN UINT64 ExitCode,
40 IN UINT64 ExitInfo1,
41 IN UINT64 ExitInfo2
42 )
43 {
44 GHCB_EVENT_INJECTION Event;
45
46 Event.Uint64 = 0;
47 Event.Elements.Vector = GP_EXCEPTION;
48 Event.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
49 Event.Elements.Valid = 1;
50
51 return Event.Uint64;
52 }
53
54 /**
55 Perform pre-VMGEXIT initialization/preparation.
56
57 Performs the necessary steps in preparation for invoking VMGEXIT. Must be
58 called before setting any fields within the GHCB.
59
60 The base library function does nothing.
61
62 @param[in, out] Ghcb A pointer to the GHCB
63
64 **/
65 VOID
66 EFIAPI
67 VmgInit (
68 IN OUT GHCB *Ghcb
69 )
70 {
71 }
72
73 /**
74 Perform post-VMGEXIT cleanup.
75
76 Performs the necessary steps to cleanup after invoking VMGEXIT. Must be
77 called after obtaining needed fields within the GHCB.
78
79 The base library function does nothing.
80
81 @param[in, out] Ghcb A pointer to the GHCB
82
83 **/
84 VOID
85 EFIAPI
86 VmgDone (
87 IN OUT GHCB *Ghcb
88 )
89 {
90 }
91
92 /**
93 Handle a #VC exception.
94
95 Performs the necessary processing to handle a #VC exception.
96
97 The base library function returns an error equal to VC_EXCEPTION,
98 to be propagated to the standard exception handling stack.
99
100 @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set
101 as value to use on error.
102 @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT
103
104 @retval EFI_SUCCESS Exception handled
105 @retval EFI_UNSUPPORTED #VC not supported, (new) exception value to
106 propagate provided
107 @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception value to
108 propagate provided
109
110 **/
111 EFI_STATUS
112 EFIAPI
113 VmgExitHandleVc (
114 IN OUT EFI_EXCEPTION_TYPE *ExceptionType,
115 IN OUT EFI_SYSTEM_CONTEXT SystemContext
116 )
117 {
118 *ExceptionType = VC_EXCEPTION;
119
120 return EFI_UNSUPPORTED;
121 }