render / rpms / edk2

Forked from rpms/edk2 3 months ago
Clone

Blame 0055-OvmfPkg-QemuFlashFvbServicesRuntimeDxe-mark-Flash-me.patch

Paolo Bonzini 83f3ca
From 966363d5a34839399e3d9f68d4f4efb4b1a9ec66 Mon Sep 17 00:00:00 2001
Paolo Bonzini 83f3ca
From: Brijesh Singh <brijesh.singh@amd.com>
Paolo Bonzini 83f3ca
Date: Fri, 6 Jul 2018 10:00:40 -0500
Paolo Bonzini 83f3ca
Subject: [PATCH] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: mark Flash memory
Paolo Bonzini 83f3ca
 range as MMIO
Paolo Bonzini 83f3ca
Paolo Bonzini 83f3ca
The flash memory range is an IO address and should be presented as Memory
Paolo Bonzini 83f3ca
Mapped IO in EFI Runtime mapping. This information can be used by OS
Paolo Bonzini 83f3ca
when mapping the flash memory range.
Paolo Bonzini 83f3ca
Paolo Bonzini 83f3ca
It is especially helpful in SEV guest case, in which IO addresses should
Paolo Bonzini 83f3ca
be mapped as unencrypted. If memory region is not marked as MMIO then OS
Paolo Bonzini 83f3ca
maps the range as encrypted.
Paolo Bonzini 83f3ca
Paolo Bonzini 83f3ca
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Paolo Bonzini 83f3ca
Cc: Anthony Perard <anthony.perard@citrix.com>
Paolo Bonzini 83f3ca
Cc: Julien Grall <julien.grall@linaro.org>
Paolo Bonzini 83f3ca
Cc: Justen Jordan L <jordan.l.justen@intel.com>
Paolo Bonzini 83f3ca
Cc: Laszlo Ersek <lersek@redhat.com>
Paolo Bonzini 83f3ca
Contributed-under: TianoCore Contribution Agreement 1.1
Paolo Bonzini 83f3ca
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Paolo Bonzini 83f3ca
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Paolo Bonzini 83f3ca
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
Paolo Bonzini 83f3ca
---
Paolo Bonzini 83f3ca
 .../FwBlockService.c                          | 30 ++++++++++++++-----
Paolo Bonzini 83f3ca
 1 file changed, 22 insertions(+), 8 deletions(-)
Paolo Bonzini 83f3ca
Paolo Bonzini 83f3ca
diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c
Paolo Bonzini 83f3ca
index 558b395dff..b3f428bb42 100644
Paolo Bonzini 83f3ca
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c
Paolo Bonzini 83f3ca
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c
Paolo Bonzini 83f3ca
@@ -831,12 +831,13 @@ ValidateFvHeader (
Paolo Bonzini 83f3ca
 
Paolo Bonzini 83f3ca
 STATIC
Paolo Bonzini 83f3ca
 EFI_STATUS
Paolo Bonzini 83f3ca
-MarkMemoryRangeForRuntimeAccess (
Paolo Bonzini 83f3ca
+MarkIoMemoryRangeForRuntimeAccess (
Paolo Bonzini 83f3ca
   EFI_PHYSICAL_ADDRESS                BaseAddress,
Paolo Bonzini 83f3ca
   UINTN                               Length
Paolo Bonzini 83f3ca
   )
Paolo Bonzini 83f3ca
 {
Paolo Bonzini 83f3ca
   EFI_STATUS                          Status;
Paolo Bonzini 83f3ca
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR     GcdDescriptor;
Paolo Bonzini 83f3ca
 
Paolo Bonzini 83f3ca
   //
Paolo Bonzini 83f3ca
   // Mark flash region as runtime memory
Paolo Bonzini 83f3ca
@@ -847,18 +848,31 @@ MarkMemoryRangeForRuntimeAccess (
Paolo Bonzini 83f3ca
                   );
Paolo Bonzini 83f3ca
 
Paolo Bonzini 83f3ca
   Status = gDS->AddMemorySpace (
Paolo Bonzini 83f3ca
-                  EfiGcdMemoryTypeSystemMemory,
Paolo Bonzini 83f3ca
+                  EfiGcdMemoryTypeMemoryMappedIo,
Paolo Bonzini 83f3ca
                   BaseAddress,
Paolo Bonzini 83f3ca
                   Length,
Paolo Bonzini 83f3ca
                   EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
Paolo Bonzini 83f3ca
                   );
Paolo Bonzini 83f3ca
   ASSERT_EFI_ERROR (Status);
Paolo Bonzini 83f3ca
 
Paolo Bonzini 83f3ca
-  Status = gBS->AllocatePages (
Paolo Bonzini 83f3ca
-                  AllocateAddress,
Paolo Bonzini 83f3ca
-                  EfiRuntimeServicesData,
Paolo Bonzini 83f3ca
-                  EFI_SIZE_TO_PAGES (Length),
Paolo Bonzini 83f3ca
-                  &BaseAddress
Paolo Bonzini 83f3ca
+  Status = gDS->AllocateMemorySpace (
Paolo Bonzini 83f3ca
+                  EfiGcdAllocateAddress,
Paolo Bonzini 83f3ca
+                  EfiGcdMemoryTypeMemoryMappedIo,
Paolo Bonzini 83f3ca
+                  0,
Paolo Bonzini 83f3ca
+                  Length,
Paolo Bonzini 83f3ca
+                  &BaseAddress,
Paolo Bonzini 83f3ca
+                  gImageHandle,
Paolo Bonzini 83f3ca
+                  NULL
Paolo Bonzini 83f3ca
+                  );
Paolo Bonzini 83f3ca
+  ASSERT_EFI_ERROR (Status);
Paolo Bonzini 83f3ca
+
Paolo Bonzini 83f3ca
+  Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);
Paolo Bonzini 83f3ca
+  ASSERT_EFI_ERROR (Status);
Paolo Bonzini 83f3ca
+
Paolo Bonzini 83f3ca
+  Status = gDS->SetMemorySpaceAttributes (
Paolo Bonzini 83f3ca
+                  BaseAddress,
Paolo Bonzini 83f3ca
+                  Length,
Paolo Bonzini 83f3ca
+                  GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME
Paolo Bonzini 83f3ca
                   );
Paolo Bonzini 83f3ca
   ASSERT_EFI_ERROR (Status);
Paolo Bonzini 83f3ca
 
Paolo Bonzini 83f3ca
@@ -1091,7 +1105,7 @@ FvbInitialize (
Paolo Bonzini 83f3ca
   //
Paolo Bonzini 83f3ca
   InstallProtocolInterfaces (FvbDevice);
Paolo Bonzini 83f3ca
 
Paolo Bonzini 83f3ca
-  MarkMemoryRangeForRuntimeAccess (BaseAddress, Length);
Paolo Bonzini 83f3ca
+  MarkIoMemoryRangeForRuntimeAccess (BaseAddress, Length);
Paolo Bonzini 83f3ca
 
Paolo Bonzini 83f3ca
   //
Paolo Bonzini 83f3ca
   // Set several PCD values to point to flash
Paolo Bonzini 83f3ca
-- 
Paolo Bonzini 83f3ca
2.17.1
Paolo Bonzini 83f3ca