]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c
OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones
[mirror_edk2.git] / OvmfPkg / QemuFlashFvbServicesRuntimeDxe / FwBlockServiceDxe.c
index 37deece363e6e586df290101653290fd09abc12b..1f285e008372b069dd26bf991342ff247d26abb0 100644 (file)
@@ -5,19 +5,14 @@
   Copyright (C) 2015, Red Hat, Inc.\r
   Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
 \r
-  This program and the accompanying materials are licensed and made available\r
-  under the terms and conditions of the BSD License which accompanies this\r
-  distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
 \r
 #include <Guid/EventGroup.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/DevicePathLib.h>\r
 #include <Library/DxeServicesTableLib.h>\r
+#include <Library/MemEncryptSevLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/UefiRuntimeLib.h>\r
@@ -49,7 +44,7 @@ InstallProtocolInterfaces (
     // LocateDevicePath fails so install a new interface and device path\r
     //\r
     FwbHandle = NULL;\r
-    DEBUG ((EFI_D_INFO, "Installing QEMU flash FVB\n"));\r
+    DEBUG ((DEBUG_INFO, "Installing QEMU flash FVB\n"));\r
     Status = gBS->InstallMultipleProtocolInterfaces (\r
                     &FwbHandle,\r
                     &gEfiFirmwareVolumeBlockProtocolGuid,\r
@@ -70,7 +65,7 @@ InstallProtocolInterfaces (
                     );\r
     ASSERT_EFI_ERROR (Status);\r
 \r
-    DEBUG ((EFI_D_INFO, "Reinstalling FVB for QEMU flash region\n"));\r
+    DEBUG ((DEBUG_INFO, "Reinstalling FVB for QEMU flash region\n"));\r
     Status = gBS->ReinstallProtocolInterface (\r
                     FwbHandle,\r
                     &gEfiFirmwareVolumeBlockProtocolGuid,\r
@@ -203,5 +198,48 @@ MarkIoMemoryRangeForRuntimeAccess (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // When SEV is active, AmdSevDxe mapped the BaseAddress with C=0 but\r
+  // SetMemorySpaceAttributes() remaps the range with C=1. Let's restore\r
+  // the mapping so that both guest and hyervisor can access the flash\r
+  // memory range.\r
+  //\r
+  if (MemEncryptSevIsEnabled ()) {\r
+    Status = MemEncryptSevClearPageEncMask (\r
+               0,\r
+               BaseAddress,\r
+               EFI_SIZE_TO_PAGES (Length),\r
+               FALSE\r
+               );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
   return Status;\r
 }\r
+\r
+VOID\r
+SetPcdFlashNvStorageBaseAddresses (\r
+  VOID\r
+  )\r
+{\r
+  RETURN_STATUS PcdStatus;\r
+\r
+  //\r
+  // Set several PCD values to point to flash\r
+  //\r
+  PcdStatus = PcdSet64S (\r
+    PcdFlashNvStorageVariableBase64,\r
+    (UINTN) PcdGet32 (PcdOvmfFlashNvStorageVariableBase)\r
+    );\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
+  PcdStatus = PcdSet32S (\r
+    PcdFlashNvStorageFtwWorkingBase,\r
+    PcdGet32 (PcdOvmfFlashNvStorageFtwWorkingBase)\r
+    );\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
+  PcdStatus = PcdSet32S (\r
+    PcdFlashNvStorageFtwSpareBase,\r
+    PcdGet32 (PcdOvmfFlashNvStorageFtwSpareBase)\r
+    );\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
+}\r