TianoCore EDK2 master
Loading...
Searching...
No Matches
PeiDxeCcExitVcHandler.c
Go to the documentation of this file.
1
9#include <Base.h>
10#include <Uefi.h>
13#include <Library/CcExitLib.h>
14#include <Register/Amd/Msr.h>
15
16#include "CcExitVcHandler.h"
17
35EFIAPI
37 IN OUT EFI_EXCEPTION_TYPE *ExceptionType,
38 IN OUT EFI_SYSTEM_CONTEXT SystemContext
39 )
40{
42 GHCB *Ghcb;
43 GHCB *GhcbBackup;
44 EFI_STATUS VcRet;
45 BOOLEAN InterruptState;
46 SEV_ES_PER_CPU_DATA *SevEsData;
47
48 InterruptState = GetInterruptState ();
49 if (InterruptState) {
51 }
52
53 Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);
54 ASSERT (Msr.GhcbInfo.Function == 0);
55 ASSERT (Msr.Ghcb != 0);
56
57 Ghcb = Msr.Ghcb;
58 GhcbBackup = NULL;
59
60 SevEsData = (SEV_ES_PER_CPU_DATA *)(Ghcb + 1);
61 SevEsData->VcCount++;
62
63 //
64 // Check for maximum PEI/DXE #VC nesting.
65 //
66 if (SevEsData->VcCount > VMGEXIT_MAXIMUM_VC_COUNT) {
67 VmgExitIssueAssert (SevEsData);
68 } else if (SevEsData->VcCount > 1) {
69 //
70 // Nested #VC
71 //
72 if (SevEsData->GhcbBackupPages == NULL) {
73 VmgExitIssueAssert (SevEsData);
74 }
75
76 //
77 // Save the active GHCB to a backup page.
78 // To access the correct backup page, increment the backup page pointer
79 // based on the current VcCount.
80 //
81 GhcbBackup = (GHCB *)SevEsData->GhcbBackupPages;
82 GhcbBackup += (SevEsData->VcCount - 2);
83
84 CopyMem (GhcbBackup, Ghcb, sizeof (*Ghcb));
85 }
86
87 VcRet = InternalVmgExitHandleVc (Ghcb, ExceptionType, SystemContext);
88
89 if (GhcbBackup != NULL) {
90 //
91 // Restore the active GHCB from the backup page.
92 //
93 CopyMem (Ghcb, GhcbBackup, sizeof (*Ghcb));
94 }
95
96 SevEsData->VcCount--;
97
98 if (InterruptState) {
100 }
101
102 return VcRet;
103}
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
BOOLEAN EFIAPI GetInterruptState(VOID)
Definition: CpuBreakpoint.c:86
VOID EFIAPI EnableInterrupts(VOID)
Definition: CpuBreakpoint.c:67
VOID EFIAPI DisableInterrupts(VOID)
Definition: CpuBreakpoint.c:54
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS EFIAPI InternalVmgExitHandleVc(IN OUT GHCB *Ghcb, IN OUT EFI_EXCEPTION_TYPE *ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
VOID EFIAPI VmgExitIssueAssert(IN OUT SEV_ES_PER_CPU_DATA *SevEsData)
#define MSR_SEV_ES_GHCB
Definition: Fam17Msr.h:24
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
Definition: GccInlinePriv.c:60
INTN EFI_EXCEPTION_TYPE
Definition: DebugSupport.h:35
EFI_STATUS EFIAPI CcExitHandleVc(IN OUT EFI_EXCEPTION_TYPE *ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29