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