]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/VirtioGpuDxe/Gop.c
SecurityPkg:Tcg: Fix comment typos
[mirror_edk2.git] / OvmfPkg / VirtioGpuDxe / Gop.c
index b3c5dae74d0e403dc34cdb6a45bef3029f97a330..936e181e8a87ab0494506bc76bdf67c0212eb859 100644 (file)
@@ -14,7 +14,6 @@
 \r
 **/\r
 \r
-#include <Library/BaseMemoryLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 \r
 #include "VirtioGpu.h"\r
@@ -115,11 +114,17 @@ ReleaseGopResources (
   }\r
 \r
   //\r
-  // Release backing pages.\r
+  // Unmap and release backing pages.\r
   //\r
-  FreePages (VgpuGop->BackingStore, VgpuGop->NumberOfPages);\r
+  VirtioGpuUnmapAndFreeBackingStore (\r
+    VgpuGop->ParentBus,      // VgpuDev\r
+    VgpuGop->NumberOfPages,  // NumberOfPages\r
+    VgpuGop->BackingStore,   // HostAddress\r
+    VgpuGop->BackingStoreMap // Mapping\r
+    );\r
   VgpuGop->BackingStore  = NULL;\r
   VgpuGop->NumberOfPages = 0;\r
+  VgpuGop->BackingStoreMap = NULL;\r
 \r
   //\r
   // Destroy the currently used 2D host resource.\r
@@ -231,11 +236,14 @@ GopSetMode (
   IN  UINT32                       ModeNumber\r
   )\r
 {\r
-  VGPU_GOP   *VgpuGop;\r
-  UINT32     NewResourceId;\r
-  UINTN      NewNumberOfBytes;\r
-  UINTN      NewNumberOfPages;\r
-  VOID       *NewBackingStore;\r
+  VGPU_GOP             *VgpuGop;\r
+  UINT32               NewResourceId;\r
+  UINTN                NewNumberOfBytes;\r
+  UINTN                NewNumberOfPages;\r
+  VOID                 *NewBackingStore;\r
+  EFI_PHYSICAL_ADDRESS NewBackingStoreDeviceAddress;\r
+  VOID                 *NewBackingStoreMap;\r
+\r
   EFI_STATUS Status;\r
   EFI_STATUS Status2;\r
 \r
@@ -294,20 +302,22 @@ GopSetMode (
   }\r
 \r
   //\r
-  // Allocate guest backing store.\r
+  // Allocate, zero and map guest backing store, for bus master common buffer\r
+  // operation.\r
   //\r
   NewNumberOfBytes = mGopResolutions[ModeNumber].Width *\r
                      mGopResolutions[ModeNumber].Height * sizeof (UINT32);\r
   NewNumberOfPages = EFI_SIZE_TO_PAGES (NewNumberOfBytes);\r
-  NewBackingStore = AllocatePages (NewNumberOfPages);\r
-  if (NewBackingStore == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
+  Status = VirtioGpuAllocateZeroAndMapBackingStore (\r
+             VgpuGop->ParentBus,            // VgpuDev\r
+             NewNumberOfPages,              // NumberOfPages\r
+             &NewBackingStore,              // HostAddress\r
+             &NewBackingStoreDeviceAddress, // DeviceAddress\r
+             &NewBackingStoreMap            // Mapping\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
     goto DestroyHostResource;\r
   }\r
-  //\r
-  // Fill visible part of backing store with black.\r
-  //\r
-  ZeroMem (NewBackingStore, NewNumberOfBytes);\r
 \r
   //\r
   // Attach backing store to the host resource.\r
@@ -315,11 +325,11 @@ GopSetMode (
   Status = VirtioGpuResourceAttachBacking (\r
              VgpuGop->ParentBus,           // VgpuDev\r
              NewResourceId,                // ResourceId\r
-             (UINTN)NewBackingStore,       // BackingStoreDeviceAddress\r
+             NewBackingStoreDeviceAddress, // BackingStoreDeviceAddress\r
              NewNumberOfPages              // NumberOfPages\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    goto FreeBackingStore;\r
+    goto UnmapAndFreeBackingStore;\r
   }\r
 \r
   //\r
@@ -392,6 +402,7 @@ GopSetMode (
   VgpuGop->ResourceId = NewResourceId;\r
   VgpuGop->BackingStore = NewBackingStore;\r
   VgpuGop->NumberOfPages = NewNumberOfPages;\r
+  VgpuGop->BackingStoreMap = NewBackingStoreMap;\r
 \r
   //\r
   // Populate Mode and ModeInfo (mutable fields only).\r
@@ -410,8 +421,13 @@ DetachBackingStore:
     CpuDeadLoop ();\r
   }\r
 \r
-FreeBackingStore:\r
-  FreePages (NewBackingStore, NewNumberOfPages);\r
+UnmapAndFreeBackingStore:\r
+  VirtioGpuUnmapAndFreeBackingStore (\r
+    VgpuGop->ParentBus, // VgpuDev\r
+    NewNumberOfPages,   // NumberOfPages\r
+    NewBackingStore,    // HostAddress\r
+    NewBackingStoreMap  // Mapping\r
+    );\r
 \r
 DestroyHostResource:\r
   Status2 = VirtioGpuResourceUnref (VgpuGop->ParentBus, NewResourceId);\r