]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/VirtioGpuDxe/Commands.c
UefiCpuPkg/MpInitLib: Optimize get processor number performance.
[mirror_edk2.git] / OvmfPkg / VirtioGpuDxe / Commands.c
index bdedea1df6a70887c0664f6a79ec38ef623853bb..6ce21976c9183d735893eef37bd1cb09833517fa 100644 (file)
@@ -90,7 +90,7 @@ VirtioGpuInit (
   //\r
   // We only want the most basic 2D features.\r
   //\r
-  Features &= VIRTIO_F_VERSION_1;\r
+  Features &= VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM;\r
 \r
   //\r
   // ... and write the subset of feature bits understood by the [...] driver to\r
@@ -211,6 +211,126 @@ VirtioGpuUninit (
   VirtioRingUninit (VgpuDev->VirtIo, &VgpuDev->Ring);\r
 }\r
 \r
+/**\r
+  Allocate, zero and map memory, for bus master common buffer operation, to be\r
+  attached as backing store to a host-side VirtIo GPU resource.\r
+\r
+  @param[in]  VgpuDev        The VGPU_DEV object that represents the VirtIo GPU\r
+                             device.\r
+\r
+  @param[in]  NumberOfPages  The number of whole pages to allocate and map.\r
+\r
+  @param[out] HostAddress    The system memory address of the allocated area.\r
+\r
+  @param[out] DeviceAddress  The bus master device address of the allocated\r
+                             area. The VirtIo GPU device may be programmed to\r
+                             access the allocated area through DeviceAddress;\r
+                             DeviceAddress is to be passed to the\r
+                             VirtioGpuResourceAttachBacking() function, as the\r
+                             BackingStoreDeviceAddress parameter.\r
+\r
+  @param[out] Mapping        A resulting token to pass to\r
+                             VirtioGpuUnmapAndFreeBackingStore().\r
+\r
+  @retval EFI_SUCCESS  The requested number of pages has been allocated, zeroed\r
+                       and mapped.\r
+\r
+  @return              Status codes propagated from\r
+                       VgpuDev->VirtIo->AllocateSharedPages() and\r
+                       VirtioMapAllBytesInSharedBuffer().\r
+**/\r
+EFI_STATUS\r
+VirtioGpuAllocateZeroAndMapBackingStore (\r
+  IN  VGPU_DEV             *VgpuDev,\r
+  IN  UINTN                NumberOfPages,\r
+  OUT VOID                 **HostAddress,\r
+  OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
+  OUT VOID                 **Mapping\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  VOID       *NewHostAddress;\r
+\r
+  Status = VgpuDev->VirtIo->AllocateSharedPages (\r
+                              VgpuDev->VirtIo,\r
+                              NumberOfPages,\r
+                              &NewHostAddress\r
+                              );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Avoid exposing stale data to the device even temporarily: zero the area\r
+  // before mapping it.\r
+  //\r
+  ZeroMem (NewHostAddress, EFI_PAGES_TO_SIZE (NumberOfPages));\r
+\r
+  Status = VirtioMapAllBytesInSharedBuffer (\r
+             VgpuDev->VirtIo,                      // VirtIo\r
+             VirtioOperationBusMasterCommonBuffer, // Operation\r
+             NewHostAddress,                       // HostAddress\r
+             EFI_PAGES_TO_SIZE (NumberOfPages),    // NumberOfBytes\r
+             DeviceAddress,                        // DeviceAddress\r
+             Mapping                               // Mapping\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    goto FreeSharedPages;\r
+  }\r
+\r
+  *HostAddress = NewHostAddress;\r
+  return EFI_SUCCESS;\r
+\r
+FreeSharedPages:\r
+  VgpuDev->VirtIo->FreeSharedPages (\r
+                     VgpuDev->VirtIo,\r
+                     NumberOfPages,\r
+                     NewHostAddress\r
+                     );\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Unmap and free memory originally allocated and mapped with\r
+  VirtioGpuAllocateZeroAndMapBackingStore().\r
+\r
+  If the memory allocated and mapped with\r
+  VirtioGpuAllocateZeroAndMapBackingStore() was attached to a host-side VirtIo\r
+  GPU resource with VirtioGpuResourceAttachBacking(), then the caller is\r
+  responsible for detaching the backing store from the same resource, with\r
+  VirtioGpuResourceDetachBacking(), before calling this function.\r
+\r
+  @param[in] VgpuDev        The VGPU_DEV object that represents the VirtIo GPU\r
+                            device.\r
+\r
+  @param[in] NumberOfPages  The NumberOfPages parameter originally passed to\r
+                            VirtioGpuAllocateZeroAndMapBackingStore().\r
+\r
+  @param[in] HostAddress    The HostAddress value originally output by\r
+                            VirtioGpuAllocateZeroAndMapBackingStore().\r
+\r
+  @param[in] Mapping        The token that was originally output by\r
+                            VirtioGpuAllocateZeroAndMapBackingStore().\r
+**/\r
+VOID\r
+VirtioGpuUnmapAndFreeBackingStore (\r
+  IN VGPU_DEV *VgpuDev,\r
+  IN UINTN    NumberOfPages,\r
+  IN VOID     *HostAddress,\r
+  IN VOID     *Mapping\r
+  )\r
+{\r
+  VgpuDev->VirtIo->UnmapSharedBuffer (\r
+                     VgpuDev->VirtIo,\r
+                     Mapping\r
+                     );\r
+  VgpuDev->VirtIo->FreeSharedPages (\r
+                     VgpuDev->VirtIo,\r
+                     NumberOfPages,\r
+                     HostAddress\r
+                     );\r
+}\r
+\r
 /**\r
   EFI_EVENT_NOTIFY function for the VGPU_DEV.ExitBoot event. It resets the\r
   VirtIo device, causing it to release its resources and to forget its\r
@@ -233,9 +353,9 @@ VirtioGpuExitBoot (
 {\r
   VGPU_DEV *VgpuDev;\r
 \r
+  DEBUG ((DEBUG_VERBOSE, "%a: Context=0x%p\n", __FUNCTION__, Context));\r
   VgpuDev = Context;\r
   VgpuDev->VirtIo->SetDeviceStatus (VgpuDev->VirtIo, 0);\r
-  VgpuDev->VirtIo->UnmapSharedBuffer (VgpuDev->VirtIo, VgpuDev->RingMap);\r
 }\r
 \r
 /**\r
@@ -496,10 +616,10 @@ VirtioGpuResourceUnref (
 \r
 EFI_STATUS\r
 VirtioGpuResourceAttachBacking (\r
-  IN OUT VGPU_DEV *VgpuDev,\r
-  IN     UINT32   ResourceId,\r
-  IN     VOID     *FirstBackingPage,\r
-  IN     UINTN    NumberOfPages\r
+  IN OUT VGPU_DEV             *VgpuDev,\r
+  IN     UINT32               ResourceId,\r
+  IN     EFI_PHYSICAL_ADDRESS BackingStoreDeviceAddress,\r
+  IN     UINTN                NumberOfPages\r
   )\r
 {\r
   volatile VIRTIO_GPU_RESOURCE_ATTACH_BACKING Request;\r
@@ -510,7 +630,7 @@ VirtioGpuResourceAttachBacking (
 \r
   Request.ResourceId    = ResourceId;\r
   Request.NrEntries     = 1;\r
-  Request.Entry.Addr    = (UINTN)FirstBackingPage;\r
+  Request.Entry.Addr    = BackingStoreDeviceAddress;\r
   Request.Entry.Length  = (UINT32)EFI_PAGES_TO_SIZE (NumberOfPages);\r
   Request.Entry.Padding = 0;\r
 \r