OvmfPkg/QemuFlashFvbServicesRuntimeDxe: mark Flash memory range as MMIO
authorBrijesh Singh <brijesh.singh@amd.com>
Fri, 6 Jul 2018 15:00:40 +0000 (10:00 -0500)
committerLaszlo Ersek <lersek@redhat.com>
Fri, 6 Jul 2018 18:07:47 +0000 (20:07 +0200)
The flash memory range is an IO address and should be presented as Memory
Mapped IO in EFI Runtime mapping. This information can be used by OS
when mapping the flash memory range.

It is especially helpful in SEV guest case, in which IO addresses should
be mapped as unencrypted. If memory region is not marked as MMIO then OS
maps the range as encrypted.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Julien Grall <julien.grall@linaro.org>
Cc: Justen Jordan L <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c

index 558b395..b3f428b 100644 (file)
@@ -831,12 +831,13 @@ ValidateFvHeader (
 \r
 STATIC\r
 EFI_STATUS\r
-MarkMemoryRangeForRuntimeAccess (\r
+MarkIoMemoryRangeForRuntimeAccess (\r
   EFI_PHYSICAL_ADDRESS                BaseAddress,\r
   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
@@ -847,18 +848,31 @@ MarkMemoryRangeForRuntimeAccess (
                   );\r
 \r
   Status = gDS->AddMemorySpace (\r
-                  EfiGcdMemoryTypeSystemMemory,\r
+                  EfiGcdMemoryTypeMemoryMappedIo,\r
                   BaseAddress,\r
                   Length,\r
                   EFI_MEMORY_UC | EFI_MEMORY_RUNTIME\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  Status = gBS->AllocatePages (\r
-                  AllocateAddress,\r
-                  EfiRuntimeServicesData,\r
-                  EFI_SIZE_TO_PAGES (Length),\r
-                  &BaseAddress\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
@@ -1091,7 +1105,7 @@ FvbInitialize (
   //\r
   InstallProtocolInterfaces (FvbDevice);\r
 \r
-  MarkMemoryRangeForRuntimeAccess (BaseAddress, Length);\r
+  MarkIoMemoryRangeForRuntimeAccess (BaseAddress, Length);\r
 \r
   //\r
   // Set several PCD values to point to flash\r