]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c
UefiCpuPkg/MpInitLib: Set the SW exit fields when performing VMGEXIT
[mirror_edk2.git] / OvmfPkg / QemuFlashFvbServicesRuntimeDxe / QemuFlashDxe.c
1 /** @file
2 OVMF support for QEMU system firmware flash device: functions specific to the
3 runtime DXE driver build.
4
5 Copyright (C) 2015, Red Hat, Inc.
6 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
7
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10 **/
11
12 #include <Library/UefiRuntimeLib.h>
13 #include <Library/MemEncryptSevLib.h>
14 #include <Library/VmgExitLib.h>
15 #include <Register/Amd/Msr.h>
16
17 #include "QemuFlash.h"
18
19 VOID
20 QemuFlashConvertPointers (
21 VOID
22 )
23 {
24 EfiConvertPointer (0x0, (VOID **) &mFlashBase);
25 }
26
27 VOID
28 QemuFlashBeforeProbe (
29 IN EFI_PHYSICAL_ADDRESS BaseAddress,
30 IN UINTN FdBlockSize,
31 IN UINTN FdBlockCount
32 )
33 {
34 //
35 // Do nothing
36 //
37 }
38
39 /**
40 Write to QEMU Flash
41
42 @param[in] Ptr Pointer to the location to write.
43 @param[in] Value The value to write.
44
45 **/
46 VOID
47 QemuFlashPtrWrite (
48 IN volatile UINT8 *Ptr,
49 IN UINT8 Value
50 )
51 {
52 if (MemEncryptSevEsIsEnabled ()) {
53 MSR_SEV_ES_GHCB_REGISTER Msr;
54 GHCB *Ghcb;
55
56 Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);
57 Ghcb = Msr.Ghcb;
58
59 //
60 // Writing to flash is emulated by the hypervisor through the use of write
61 // protection. This won't work for an SEV-ES guest because the write won't
62 // be recognized as a true MMIO write, which would result in the required
63 // #VC exception. Instead, use the the VMGEXIT MMIO write support directly
64 // to perform the update.
65 //
66 VmgInit (Ghcb);
67 Ghcb->SharedBuffer[0] = Value;
68 Ghcb->SaveArea.SwScratch = (UINT64) (UINTN) Ghcb->SharedBuffer;
69 VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, (UINT64) (UINTN) Ptr, 1);
70 VmgDone (Ghcb);
71 } else {
72 *Ptr = Value;
73 }
74 }