]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c
OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Do not expose MMIO in SMM build
[mirror_edk2.git] / OvmfPkg / QemuFlashFvbServicesRuntimeDxe / FwBlockServiceDxe.c
index 63b308658e36b4ef91f1e098f01e504c965fead7..37deece363e6e586df290101653290fd09abc12b 100644 (file)
@@ -17,6 +17,7 @@
 #include <Guid/EventGroup.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/DevicePathLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/UefiRuntimeLib.h>\r
@@ -155,3 +156,52 @@ InstallVirtualAddressChangeHandler (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
+\r
+EFI_STATUS\r
+MarkIoMemoryRangeForRuntimeAccess (\r
+  IN EFI_PHYSICAL_ADDRESS                BaseAddress,\r
+  IN UINTN                               Length\r
+  )\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR     GcdDescriptor;\r
+\r
+  //\r
+  // Mark flash region as runtime memory\r
+  //\r
+  Status = gDS->RemoveMemorySpace (\r
+                  BaseAddress,\r
+                  Length\r
+                  );\r
+\r
+  Status = gDS->AddMemorySpace (\r
+                  EfiGcdMemoryTypeMemoryMappedIo,\r
+                  BaseAddress,\r
+                  Length,\r
+                  EFI_MEMORY_UC | EFI_MEMORY_RUNTIME\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gDS->AllocateMemorySpace (\r
+                  EfiGcdAllocateAddress,\r
+                  EfiGcdMemoryTypeMemoryMappedIo,\r
+                  0,\r
+                  Length,\r
+                  &BaseAddress,\r
+                  gImageHandle,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gDS->SetMemorySpaceAttributes (\r
+                  BaseAddress,\r
+                  Length,\r
+                  GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r