diff options
author | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
---|---|---|
committer | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /roms/edk2/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'roms/edk2/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c')
-rw-r--r-- | roms/edk2/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/roms/edk2/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c b/roms/edk2/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c new file mode 100644 index 000000000..7eb80bfef --- /dev/null +++ b/roms/edk2/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c @@ -0,0 +1,64 @@ +/** @file
+ Define the module hooks used while probing the QEMU flash device.
+
+ Copyright (C) 2018, Advanced Micro Devices. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
+#include <Library/MemEncryptSevLib.h>
+
+#include "QemuFlash.h"
+
+VOID
+QemuFlashBeforeProbe (
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINTN FdBlockSize,
+ IN UINTN FdBlockCount
+ )
+{
+ EFI_STATUS Status;
+
+ ASSERT (FeaturePcdGet (PcdSmmSmramRequire));
+
+ if (!MemEncryptSevIsEnabled ()) {
+ return;
+ }
+
+ //
+ // When SEV is enabled, AmdSevDxe runs early in DXE phase and clears the
+ // C-bit from the NonExistent entry -- which is later split and accommodate
+ // the flash MMIO but the driver runs in non SMM context hence it cleared the
+ // flash ranges from non SMM page table. When SMM is enabled, the flash
+ // services are accessed from the SMM mode hence we explicitly clear the
+ // C-bit on flash ranges from SMM page table.
+ //
+
+ Status = MemEncryptSevClearPageEncMask (
+ 0,
+ BaseAddress,
+ EFI_SIZE_TO_PAGES (FdBlockSize * FdBlockCount),
+ FALSE
+ );
+ ASSERT_EFI_ERROR (Status);
+}
+
+/**
+ Write to QEMU Flash
+
+ @param[in] Ptr Pointer to the location to write.
+ @param[in] Value The value to write.
+
+**/
+VOID
+QemuFlashPtrWrite (
+ IN volatile UINT8 *Ptr,
+ IN UINT8 Value
+ )
+{
+ *Ptr = Value;
+}
|