]> 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 c6ff9ed57461a0567f1a750e100dafef38bb1a95..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
@@ -204,7 +209,7 @@ GopQueryMode (
 {\r
   EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *GopModeInfo;\r
 \r
-  if (ModeNumber >= sizeof mGopResolutions / sizeof mGopResolutions[0]) {\r
+  if (ModeNumber >= ARRAY_SIZE (mGopResolutions)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -231,15 +236,18 @@ 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
-  if (ModeNumber >= sizeof mGopResolutions / sizeof mGopResolutions[0]) {\r
+  if (ModeNumber >= ARRAY_SIZE (mGopResolutions)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -258,8 +266,7 @@ GopSetMode (
     //\r
     VgpuGop->Gop.Mode = &VgpuGop->GopMode;\r
 \r
-    VgpuGop->GopMode.MaxMode         = (UINT32)(sizeof mGopResolutions /\r
-                                                sizeof mGopResolutions[0]);\r
+    VgpuGop->GopMode.MaxMode         = (UINT32)(ARRAY_SIZE (mGopResolutions));\r
     VgpuGop->GopMode.Info            = &VgpuGop->GopModeInfo;\r
     VgpuGop->GopMode.SizeOfInfo      = sizeof VgpuGop->GopModeInfo;\r
 \r
@@ -295,32 +302,34 @@ 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
   //\r
   Status = VirtioGpuResourceAttachBacking (\r
-             VgpuGop->ParentBus, // VgpuDev\r
-             NewResourceId,      // ResourceId\r
-             NewBackingStore,    // FirstBackingPage\r
-             NewNumberOfPages    // NumberOfPages\r
+             VgpuGop->ParentBus,           // VgpuDev\r
+             NewResourceId,                // ResourceId\r
+             NewBackingStoreDeviceAddress, // BackingStoreDeviceAddress\r
+             NewNumberOfPages              // NumberOfPages\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    goto FreeBackingStore;\r
+    goto UnmapAndFreeBackingStore;\r
   }\r
 \r
   //\r
@@ -393,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
@@ -411,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