TianoCore EDK2 master
Loading...
Searching...
No Matches
QemuFlashDxe.c
Go to the documentation of this file.
1
14#include <Library/CcExitLib.h>
15#include <Register/Amd/Msr.h>
16
17#include "QemuFlash.h"
18
19STATIC EFI_PHYSICAL_ADDRESS mSevEsFlashPhysBase;
20
21VOID
22QemuFlashConvertPointers (
23 VOID
24 )
25{
27 mSevEsFlashPhysBase = (UINTN)mFlashBase;
28 }
29
30 EfiConvertPointer (0x0, (VOID **)&mFlashBase);
31}
32
33VOID
34QemuFlashBeforeProbe (
35 IN EFI_PHYSICAL_ADDRESS BaseAddress,
36 IN UINTN FdBlockSize,
37 IN UINTN FdBlockCount
38 )
39{
40 //
41 // Do nothing
42 //
43}
44
52VOID
54 IN volatile UINT8 *Ptr,
55 IN UINT8 Value
56 )
57{
60 GHCB *Ghcb;
61 EFI_PHYSICAL_ADDRESS PhysAddr;
62 BOOLEAN InterruptState;
63
64 Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);
65 Ghcb = Msr.Ghcb;
66
67 //
68 // The MMIO write needs to be to the physical address of the flash pointer.
69 // Since this service is available as part of the EFI runtime services,
70 // account for a non-identity mapped VA after SetVirtualAddressMap().
71 //
72 if (mSevEsFlashPhysBase == 0) {
73 PhysAddr = (UINTN)Ptr;
74 } else {
75 PhysAddr = mSevEsFlashPhysBase + (Ptr - mFlashBase);
76 }
77
78 //
79 // Writing to flash is emulated by the hypervisor through the use of write
80 // protection. This won't work for an SEV-ES guest because the write won't
81 // be recognized as a true MMIO write, which would result in the required
82 // #VC exception. Instead, use the VMGEXIT MMIO write support directly
83 // to perform the update.
84 //
85 CcExitVmgInit (Ghcb, &InterruptState);
86 Ghcb->SharedBuffer[0] = Value;
87 Ghcb->SaveArea.SwScratch = (UINT64)(UINTN)Ghcb->SharedBuffer;
88 CcExitVmgSetOffsetValid (Ghcb, GhcbSwScratch);
89 CcExitVmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, PhysAddr, 1);
90 CcExitVmgDone (Ghcb, InterruptState);
91 } else {
92 *Ptr = Value;
93 }
94}
UINT64 UINTN
UINT64 EFIAPI CcExitVmgExit(IN OUT GHCB *Ghcb, IN UINT64 ExitCode, IN UINT64 ExitInfo1, IN UINT64 ExitInfo2)
Definition: CcExitLib.c:106
VOID EFIAPI CcExitVmgSetOffsetValid(IN OUT GHCB *Ghcb, IN GHCB_REGISTER Offset)
Definition: CcExitLib.c:198
VOID EFIAPI CcExitVmgInit(IN OUT GHCB *Ghcb, IN OUT BOOLEAN *InterruptState)
Definition: CcExitLib.c:146
VOID EFIAPI CcExitVmgDone(IN OUT GHCB *Ghcb, IN BOOLEAN InterruptState)
Definition: CcExitLib.c:176
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
Definition: GccInlinePriv.c:60
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
BOOLEAN EFIAPI MemEncryptSevEsIsEnabled(VOID)
VOID QemuFlashPtrWrite(IN volatile UINT8 *Ptr, IN UINT8 Value)
Definition: QemuFlashDxe.c:53
#define MSR_SEV_ES_GHCB
Definition: SevSnpMsr.h:24
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
EFI_STATUS EFIAPI EfiConvertPointer(IN UINTN DebugDisposition, IN OUT VOID **Address)
Definition: RuntimeLib.c:561