]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioGpuDxe: map VRING for bus master common buffer operation
authorLaszlo Ersek <lersek@redhat.com>
Sat, 26 Aug 2017 14:00:30 +0000 (16:00 +0200)
committerLaszlo Ersek <lersek@redhat.com>
Fri, 1 Sep 2017 12:27:28 +0000 (14:27 +0200)
VirtioGpuDxe uses one virtio ring, for VIRTIO_GPU_CONTROL_QUEUE.

Map it for bus master common buffer operation with VirtioRingMap(), so
that it can be accessed equally by both guest and hypervisor even if an
IOMMU is used. (VirtioRingInit() already allocates the ring suitably for
this, see commit b0338c53297c, "OvmfPkg/VirtioLib: alloc VRING buffer with
AllocateSharedPages()", 2017-08-23).

Pass the resultant translation offset ("RingBaseShift"), from system
memory address to bus master device address, to VIRTIO_SET_QUEUE_ADDRESS.

Unmap the ring in all contexts where the ring becomes unused (these
contexts are mutually exclusive):

- in VirtioGpuInit(): the ring has been mapped, but we cannot complete the
  virtio initialization for another reason,

- in VirtioGpuUninit(): the virtio initialization has succeeded, but
  VirtioGpuDriverBindingStart() fails for another reason, or
  VirtioGpuDriverBindingStop() unbinds the device after use,

- in VirtioGpuExitBoot(): ExitBootServices() is called after
  VirtioGpuDriverBindingStart() has successfully bound the device.
  (Unmapping the ring does not change the UEFI memory map.)

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Brijesh Singh <brijesh.singh@amd.com>
OvmfPkg/VirtioGpuDxe/Commands.c
OvmfPkg/VirtioGpuDxe/VirtioGpu.h

index 5cb0031612077ea0bc096765d9f2f48773d8f826..4e19bac606eea0d1fda3e757344c49b3dbb784f5 100644 (file)
@@ -44,6 +44,7 @@ VirtioGpuInit (
   EFI_STATUS Status;\r
   UINT64     Features;\r
   UINT16     QueueSize;\r
+  UINT64     RingBaseShift;\r
 \r
   //\r
   // Execute virtio-v1.0-cs04, 3.1.1 Driver Requirements: Device\r
@@ -132,13 +133,28 @@ VirtioGpuInit (
   if (EFI_ERROR (Status)) {\r
     goto Failed;\r
   }\r
+  //\r
+  // If anything fails from here on, we have to release the ring.\r
+  //\r
+  Status = VirtioRingMap (\r
+             VgpuDev->VirtIo,\r
+             &VgpuDev->Ring,\r
+             &RingBaseShift,\r
+             &VgpuDev->RingMap\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ReleaseQueue;\r
+  }\r
+  //\r
+  // If anything fails from here on, we have to unmap the ring.\r
+  //\r
   Status = VgpuDev->VirtIo->SetQueueAddress (\r
                               VgpuDev->VirtIo,\r
                               &VgpuDev->Ring,\r
-                              0\r
+                              RingBaseShift\r
                               );\r
   if (EFI_ERROR (Status)) {\r
-    goto ReleaseQueue;\r
+    goto UnmapQueue;\r
   }\r
 \r
   //\r
@@ -147,11 +163,14 @@ VirtioGpuInit (
   NextDevStat |= VSTAT_DRIVER_OK;\r
   Status = VgpuDev->VirtIo->SetDeviceStatus (VgpuDev->VirtIo, NextDevStat);\r
   if (EFI_ERROR (Status)) {\r
-    goto ReleaseQueue;\r
+    goto UnmapQueue;\r
   }\r
 \r
   return EFI_SUCCESS;\r
 \r
+UnmapQueue:\r
+  VgpuDev->VirtIo->UnmapSharedBuffer (VgpuDev->VirtIo, VgpuDev->RingMap);\r
+\r
 ReleaseQueue:\r
   VirtioRingUninit (VgpuDev->VirtIo, &VgpuDev->Ring);\r
 \r
@@ -188,6 +207,7 @@ VirtioGpuUninit (
   // configuration.\r
   //\r
   VgpuDev->VirtIo->SetDeviceStatus (VgpuDev->VirtIo, 0);\r
+  VgpuDev->VirtIo->UnmapSharedBuffer (VgpuDev->VirtIo, VgpuDev->RingMap);\r
   VirtioRingUninit (VgpuDev->VirtIo, &VgpuDev->Ring);\r
 }\r
 \r
@@ -215,6 +235,7 @@ VirtioGpuExitBoot (
 \r
   VgpuDev = Context;\r
   VgpuDev->VirtIo->SetDeviceStatus (VgpuDev->VirtIo, 0);\r
+  VgpuDev->VirtIo->UnmapSharedBuffer (VgpuDev->VirtIo, VgpuDev->RingMap);\r
 }\r
 \r
 /**\r
index 078b7d44d83e994bf93ee121d8ef81fd42a82f78..193e932e1430efa516cc759f74c12a38b6400522 100644 (file)
@@ -55,6 +55,12 @@ typedef struct {
   //\r
   VRING                    Ring;\r
 \r
+  //\r
+  // Token associated with Ring's mapping for bus master common buffer\r
+  // operation, from VirtioRingMap().\r
+  //\r
+  VOID                     *RingMap;\r
+\r
   //\r
   // Event to be signaled at ExitBootServices().\r
   //\r